혼자 고민해보기_ 개발/TIL (Today I Learned)
20230904(월)_ 최종프로젝트 진행
nuri-story
2023. 9. 4. 22:04
금일 달성 항목
1) front 연결
: 메인 company, jobposting 불러오고 상세페이지 연동
: apply 연결
문제 해결 과정 1 - apply 연결 (채용공고 지원내역 확인 페이지)
[문제]
기업은 본인이 업로드한 채용공고를 구직자는 지원한 공고를 확인 할 수 있는 영역을 만들어 사용성을 높이고자 하였습니다.
그런데 ejs에서 연결을 어떻게 해야하는지 문제가 있었습니다.
[시도 및 해결]
처음에는 아래와 같은 코드로 작성을했는데 이렇게하니 apply파일을 views에서 찾을 수 없다는 에러메세지가 나왔습니다.
@Get('apply/:type')
async getApply(
@Request() req,
@Param('type') type: string,
@Res() res: Response,
) {
const cookie: string = await req.cookies['authorization'];
if (cookie) {
if (type === 'user') {
return res.render('apply-user'); // 타입이 유저면 apply-user를 랜더링
} else if (type === 'company') {
return res.render('apply-company'); // 타입이 회사면 apply-company 랜더링
}
}
return res.render('apply', {
type,
});
}
그래서 해당 분기를 apply.js 한곳에서 에서 처리하고 그 안에서 구분하는 식으로 진행하고자 합니다.
우선 controller에서 아래와 같이 수정하였습니다.
// 채용공고 지원 내역 보기
@Get('apply/:type')
async getApply(
@Request() req,
@Param('type') type: string,
@Res() res: Response,
) {
const cookie: string = await req.cookies['authorization'];
if (!cookie) {
return res.redirect('/singin'); // 쿠키가 없으면 로그인하게 이동
}
return res.render('apply', {
type,
isLogin: 1,
});
}
[알게된 점]
프론트 공부를하면서 하니 너무 더딥니다 ㅠㅠ 최대한 해보려고 합니다.