-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1257 from Daggahh/dev
feat(jobs): implement job post update endpoint and add comprehensive tests
- Loading branch information
Showing
8 changed files
with
419 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { Job } from '../modules/jobs/entities/job.entity'; | ||
|
||
@Injectable() | ||
export class JobOwnerGuard implements CanActivate { | ||
constructor( | ||
@InjectRepository(Job) | ||
private readonly jobRepository: Repository<Job> | ||
) {} | ||
|
||
async canActivate(context: ExecutionContext): Promise<boolean> { | ||
const request = context.switchToHttp().getRequest(); | ||
const jobId = request.params.id; | ||
const userId = request.user.sub; | ||
|
||
if (!jobId || !userId) return false; | ||
|
||
const job = await this.jobRepository.findOne({ | ||
where: { id: jobId }, | ||
relations: ['user'], | ||
}); | ||
|
||
if (!job) return false; | ||
|
||
return job.user.id === userId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { ApiPropertyOptional } from '@nestjs/swagger'; | ||
import { IsOptional, IsString, IsEnum, IsDateString, IsArray } from 'class-validator'; | ||
import { JobMode, JobType, SalaryRange } from './job.dto'; | ||
|
||
export class UpdateJobDto { | ||
@ApiPropertyOptional({ | ||
description: 'The title of the job', | ||
example: 'Senior Software Engineer', | ||
}) | ||
@IsOptional() | ||
@IsString() | ||
title?: string; | ||
|
||
@ApiPropertyOptional({ | ||
description: 'A detailed description of the job', | ||
example: 'We are looking for an experienced developer...', | ||
}) | ||
@IsOptional() | ||
@IsString() | ||
description?: string; | ||
|
||
@ApiPropertyOptional({ | ||
description: 'The location of the job', | ||
example: 'New York, NY', | ||
}) | ||
@IsOptional() | ||
@IsString() | ||
location?: string; | ||
|
||
@ApiPropertyOptional({ | ||
description: 'The deadline for applications', | ||
example: '2024-12-31T23:59:59Z', | ||
}) | ||
@IsOptional() | ||
@IsDateString() | ||
deadline?: string; | ||
|
||
@ApiPropertyOptional({ | ||
description: 'The salary range', | ||
enum: SalaryRange, | ||
}) | ||
@IsOptional() | ||
@IsEnum(SalaryRange) | ||
salary_range?: string; | ||
|
||
@ApiPropertyOptional({ | ||
description: 'The type of job', | ||
enum: JobType, | ||
}) | ||
@IsOptional() | ||
@IsEnum(JobType) | ||
job_type?: string; | ||
|
||
@ApiPropertyOptional({ | ||
description: 'The mode of work', | ||
enum: JobMode, | ||
}) | ||
@IsOptional() | ||
@IsEnum(JobMode) | ||
job_mode?: string; | ||
|
||
@ApiPropertyOptional({ | ||
description: 'Company name', | ||
example: 'Tech Corp', | ||
}) | ||
@IsOptional() | ||
@IsString() | ||
company_name?: string; | ||
|
||
@ApiPropertyOptional({ | ||
description: 'Required qualifications', | ||
type: [String], | ||
}) | ||
@IsOptional() | ||
@IsArray() | ||
qualifications?: string[]; | ||
|
||
@ApiPropertyOptional({ | ||
description: 'Key responsibilities', | ||
type: [String], | ||
}) | ||
@IsOptional() | ||
@IsArray() | ||
key_responsibilities?: string[]; | ||
|
||
@ApiPropertyOptional({ | ||
description: 'Job benefits', | ||
type: [String], | ||
}) | ||
@IsOptional() | ||
@IsArray() | ||
benefits?: string[]; | ||
|
||
@ApiPropertyOptional({ | ||
description: 'Required experience level', | ||
example: 'Senior', | ||
}) | ||
@IsOptional() | ||
@IsString() | ||
experience_level?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.