Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add date selection in applicants #169

Merged
merged 1 commit into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/modules/job/controllers/job.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class JobController extends BaseController<Job> {
job,
page: pagerDetails.page - 1,
size: pagerDetails.pageSize,
query,
});
if (applicants !== undefined) {
const pager = {
Expand Down
29 changes: 26 additions & 3 deletions src/modules/job/services/job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,32 @@ export class JobService extends BaseService<Job> {
message: `You have successfully applied to with name <${job.name}>`,
};
}
async applicants({ job, size, page }): Promise<any> {
const query = `SELECT *, COUNT(*) OVER() AS COUNT FROM (SELECT * FROM APPLIEDJOB WHERE JOBID=${job.id}) AS TBL OFFSET ${page} LIMIT ${size}`;
const jobApplicants = await this.repository.manager.query(query);
async applicants({ job, size, page, query }): Promise<any> {
let sql = `SELECT *, COUNT(*) OVER() AS COUNT FROM (SELECT * FROM APPLIEDJOB WHERE JOBID=${job.id}) AS TBL OFFSET ${page} LIMIT ${size}`;
if (Object.keys(query).length > 0) {
if (query.startDate && query.endDate) {
const date = new Date(query.startDate);
date.setDate(date.getDate() - 1);
const startdate = date.toISOString().split('T')[0];
const dates = new Date(query.endDate);
dates.setDate(dates.getDate() + 1);
const enddate = dates.toISOString().split('T')[0];
sql = `SELECT *, COUNT(*) OVER() AS COUNT FROM (SELECT * FROM APPLIEDJOB A WHERE A.JOBID=${job.id} AND A.DATE >= '${startdate}' AND A.DATE <='${enddate}') AS TBL OFFSET ${page} LIMIT ${size}`;
}
if (query.startDtae && !query.endDate) {
const date = new Date(query.startDate);
date.setDate(date.getDate() - 1);
const startdate = date.toISOString().split('T')[0];
sql = `SELECT *, COUNT(*) OVER() AS COUNT FROM (SELECT * FROM APPLIEDJOB A WHERE A.JOBID=${job.id} AND A.DATE >= '${startdate}') AS TBL OFFSET ${page} LIMIT ${size}`;
}
if (query.endDtae && !query.startDate) {
const dates = new Date(query.endDate);
dates.setDate(dates.getDate() + 1);
const enddate = dates.toISOString().split('T')[0];
sql = `SELECT *, COUNT(*) OVER() AS COUNT FROM (SELECT * FROM APPLIEDJOB A WHERE A.JOBID=${job.id} AND A.DATE <='${enddate}') AS TBL OFFSET ${page} LIMIT ${size}`;
}
}
const jobApplicants = await this.repository.manager.query(sql);
if (jobApplicants.length > 0) {
let applicants = jobApplicants.map(async (data: { userid: any }) => {
const user = await this.userrepository.findOne({
Expand Down
12 changes: 12 additions & 0 deletions src/modules/user/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,16 @@ export class AuthController {
const user = await this.authService.userInfo(req.user.id, query.fields);
return res.status(HttpStatus.OK).send(resolveResponse(user));
}

@Get('companymetrics')
@UseFilters(new HttpErrorFilter())
@UseGuards(AuthGuard('jwt'))
async companynmetrics(
@Req() req: any,
@Res() res: any,
@Query() query: any,
): Promise<any> {
const user = await this.authService.userInfo(req.user.id, query.fields);
return res.status(HttpStatus.OK).send(resolveResponse(user));
}
}