-
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 branch 'hngprojects:dev' into feat/dislike_comment
- Loading branch information
Showing
16 changed files
with
172 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { Job } from '../modules/jobs/entities/job.entity'; | ||
import { User } from '@modules/user/entities/user.entity'; | ||
|
||
@Injectable() | ||
export class JobAccessGuard implements CanActivate { | ||
constructor( | ||
@InjectRepository(Job) | ||
private readonly jobRepository: Repository<Job>, | ||
@InjectRepository(User) | ||
private readonly userRepository: Repository<User> | ||
) {} | ||
|
||
async canActivate(context: ExecutionContext): Promise<boolean> { | ||
const request = context.switchToHttp().getRequest(); | ||
const jobId = request.params.id; | ||
const userId = request.user.sub; | ||
|
||
const user = await this.userRepository.findOne({ | ||
where: { id: userId }, | ||
}); | ||
|
||
if (user?.is_superadmin) { | ||
return true; | ||
} | ||
|
||
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 |
---|---|---|
|
@@ -39,4 +39,4 @@ export class ContactUsService { | |
}, | ||
}); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
import { IsEmail, IsNotEmpty, IsOptional, IsString, Matches } from 'class-validator'; | ||
|
||
export class CreateContactDto { | ||
@IsNotEmpty({ message: 'Name should not be empty' }) | ||
@IsString({ message: 'Name must be a string' }) | ||
name: string; | ||
@IsNotEmpty({ message: 'Name should not be empty' }) | ||
@IsString({ message: 'Name must be a string' }) | ||
name: string; | ||
|
||
@IsNotEmpty({ message: 'Email should not be empty' }) | ||
@IsEmail({}, { message: 'Email must be valid' }) | ||
email: string; | ||
@IsNotEmpty({ message: 'Email should not be empty' }) | ||
@IsEmail({}, { message: 'Email must be valid' }) | ||
email: string; | ||
|
||
@IsOptional() | ||
@IsString({ message: 'Phone must be a string' }) | ||
@Matches(/^\+?[0-9\-\s()]{8,20}$/, { | ||
message: 'Invalid phone number format' | ||
}) | ||
phone: string; | ||
@IsOptional() | ||
@IsString({ message: 'Phone must be a string' }) | ||
@Matches(/^\+?[0-9\-\s()]{8,20}$/, { | ||
message: 'Invalid phone number format', | ||
}) | ||
phone: string; | ||
|
||
@IsNotEmpty({ message: 'Message should not be empty' }) | ||
@IsString({ message: 'Message must be a string' }) | ||
message: string; | ||
} | ||
@IsNotEmpty({ message: 'Message should not be empty' }) | ||
@IsString({ message: 'Message must be a string' }) | ||
message: 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
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
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 |
---|---|---|
|
@@ -33,4 +33,5 @@ export const mockUser = { | |
comments: null, | ||
cart: [], | ||
organisations: null, | ||
is_superadmin: false, | ||
}; |
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