From ac45847cbafee6b68825e1af577d259445f23420 Mon Sep 17 00:00:00 2001 From: Bennett Date: Mon, 23 Aug 2021 00:12:00 +0300 Subject: [PATCH] add location and date for interview close #138 --- .../user/controllers/user.controller.ts | 28 ++++++++++++++++++- src/modules/user/services/user.service.ts | 10 ++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/modules/user/controllers/user.controller.ts b/src/modules/user/controllers/user.controller.ts index 4d206c4..7e85f0f 100644 --- a/src/modules/user/controllers/user.controller.ts +++ b/src/modules/user/controllers/user.controller.ts @@ -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 { + 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, @@ -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 diff --git a/src/modules/user/services/user.service.ts b/src/modules/user/services/user.service.ts index b2d8252..b2b7735 100644 --- a/src/modules/user/services/user.service.ts +++ b/src/modules/user/services/user.service.ts @@ -107,7 +107,7 @@ export class UserService extends BaseService { } } async interview({ job, user }): Promise { - 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`, @@ -121,4 +121,12 @@ export class UserService extends BaseService { message: `<${user.firstname} ${user.lastname}'s> application has been rejected`, }; } + + async accept({ job, user }): Promise { + 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}>`, + }; + } }