Skip to content

Commit

Permalink
feat upd recruitment-session: service, controller, entity
Browse files Browse the repository at this point in the history
  • Loading branch information
whiitex committed Dec 28, 2023
1 parent 97aa948 commit 7f1e3d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 55 deletions.
26 changes: 0 additions & 26 deletions api/src/recruitment-session/recruitment-session.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,32 +126,6 @@ export class RecruitmentSessionController {
);
}

// DELETE A RECRUITMENT SESSION BY START & END DATE
@ApiBadRequestResponse()
@ApiForbiddenResponse()
@ApiNotFoundResponse()
@ApiOkResponse()
@ApiNoContentResponse()
@CheckPolicies((ability) => ability.can(Action.Delete, 'RecruitmentSession'))
// @Delete('/:time_slot_id')
// @JoiValidate({
// param: Joi.number().positive().integer().required().label('time_slot_id'),
// })
async deleteTimeSlotByStartEnd(
@Param('start') startDate: Date,
@Param('end') endDate: Date,
): Promise<RecruitmentSession> {
const toRemove =
await this.recruitmentSessionService.findRecruitmentSessionByStartEndDate(
startDate,
endDate,
);
if (!toRemove) throw new NotFoundException('Recruitment session not found');
return await this.recruitmentSessionService.deletRecruitmentSession(
toRemove,
);
}

// DELETE A RECRUITMENT SESSION
@ApiBadRequestResponse()
@ApiForbiddenResponse()
Expand Down
36 changes: 7 additions & 29 deletions api/src/recruitment-session/recruitment-session.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ export class RecruitmentSessionService {
async createRecruitmentSession(
recruitmentSession: CreateRecruitmentSessionDto,
): Promise<RecruitmentSession> {
let rs = await this.recruitmentSessionRepository.save(recruitmentSession);
rs.state = RecruitmentSessionState.Active;
let now = new Date();
rs.createdAt = now;
rs.lastModified = now;
const rs = {
...recruitmentSession,
state: RecruitmentSessionState.Active,
createdAt: now,
lastModified: now,
} as RecruitmentSession;
await this.recruitmentSessionRepository.save(rs);
return rs;
}

Expand All @@ -37,19 +40,9 @@ export class RecruitmentSessionService {
});
}

async findRecruitmentSessionByStartEndDate(
start: Date,
end: Date,
): Promise<RecruitmentSession> {
return await this.recruitmentSessionRepository.findOne({
where: { interviewStart: start, interviewEnd: end },
});
}

async deletRecruitmentSession(
recruitmentSession: RecruitmentSession,
): Promise<RecruitmentSession> {
// let toRemove = await this.findRecruitmentSessionByStartEndDate(start, end);
return await this.recruitmentSessionRepository.remove(recruitmentSession);
}

Expand All @@ -58,19 +51,4 @@ export class RecruitmentSessionService {
): Promise<RecruitmentSession> {
return await this.recruitmentSessionRepository.save(recruitmentSession);
}

// udpate state active with respect to current date
async updateAllStates() {
let now: number = new Date().getTime();
let list: RecruitmentSession[] =
await this.recruitmentSessionRepository.find({
where: { state: RecruitmentSessionState.Active },
});
list.forEach((recruitmentSession) => {
if (now >= recruitmentSession.interviewEnd.getTime()) {
recruitmentSession.state = RecruitmentSessionState.Concluded;
this.updateRecruitmentSession(recruitmentSession);
}
});
}
}

0 comments on commit 7f1e3d8

Please sign in to comment.