Skip to content

Commit

Permalink
add location and date for interview
Browse files Browse the repository at this point in the history
close #138
  • Loading branch information
BaharaJr committed Aug 22, 2021
1 parent 2e445d2 commit ac45847
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
28 changes: 27 additions & 1 deletion src/modules/user/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,32 @@ export class UserController {
@Post(':id/interview')
@UseGuards(AuthGuard('jwt'))
async interview(
@Body() body: { job: string; location: string; date: Date },
@Param() param: { id: string },
@Res() res: any,
): Promise<any> {
let job: any = await this.service.findJob(body.job);
const user = await this.service.findOneByUid(param.id);
if (job) {
if (user) {
job = { ...job, ...body };
const callForInterview = await this.service.interview({ job, user });
return res.status(HttpStatus.OK).send(callForInterview.message);
} else {
return res
.status(HttpStatus.NOT_FOUND)
.send(`User with ID ${param.id} could not be found`);
}
} else {
return res
.status(HttpStatus.NOT_FOUND)
.send(`Job with ID ${body.job} could not be found`);
}
}

@Post(':id/accept')
@UseGuards(AuthGuard('jwt'))
async accept(
@Body() body: { job: string },
@Param() param: { id: string },
@Res() res: any,
Expand All @@ -148,7 +174,7 @@ export class UserController {
const user = await this.service.findOneByUid(param.id);
if (job) {
if (user) {
const callForInterview = await this.service.interview({ job, user });
const callForInterview = await this.service.accept({ job, user });
return res.status(HttpStatus.OK).send(callForInterview.message);
} else {
return res
Expand Down
10 changes: 9 additions & 1 deletion src/modules/user/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class UserService extends BaseService<User> {
}
}
async interview({ job, user }): Promise<any> {
const query = `UPDATE APPLIEDJOB SET INTERVIEW=TRUE WHERE USERID=${user.id} AND JOBID=${job.id}`;
const query = `UPDATE APPLIEDJOB SET INTERVIEW=TRUE, DATE='${job.date}', LOCATION='${job.location}' WHERE USERID=${user.id} AND JOBID=${job.id}`;
await this.repository.manager.query(query);
return {
message: `<${user.firstname} ${user.lastname}> has been invited for the interview`,
Expand All @@ -121,4 +121,12 @@ export class UserService extends BaseService<User> {
message: `<${user.firstname} ${user.lastname}'s> application has been rejected`,
};
}

async accept({ job, user }): Promise<any> {
const query = `UPDATE APPLIEDJOB SET ACCEPTED=TRUE WHERE USERID=${user.id} AND JOBID=${job.id}`;
await this.repository.manager.query(query);
return {
message: `You have accepted the call for interview for job <${job.name}>`,
};
}
}

0 comments on commit ac45847

Please sign in to comment.