-
Notifications
You must be signed in to change notification settings - Fork 0
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 #35 from richard483/feature/run-week-1
Feature/run week 1
- Loading branch information
Showing
22 changed files
with
590 additions
and
36 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
8 changes: 8 additions & 0 deletions
8
prisma/migrations/20231129055941_updated_user_field/migration.sql
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,8 @@ | ||
-- AlterEnum | ||
ALTER TYPE "Role" ADD VALUE 'RECRUITER'; | ||
|
||
-- AlterTable | ||
ALTER TABLE "User" ADD COLUMN "companyId" TEXT; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "User" ADD CONSTRAINT "User_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "Company"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export enum Role { | ||
ADMIN = 'ADMIN', | ||
USER = 'USER', | ||
RECRUITER = 'RECRUITER', | ||
} |
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,44 @@ | ||
function pagination(page: number, size: number) { | ||
if (!page || page < 1) { | ||
page = 1; | ||
} | ||
if (!size || size < 1) { | ||
size = 5; | ||
} | ||
const skip = (page - 1) * size; | ||
const take = size; | ||
return { | ||
skip, | ||
take, | ||
}; | ||
} | ||
|
||
function returnablePaginated( | ||
data: any, | ||
total: number, | ||
page: number, | ||
size: number, | ||
) { | ||
if (!page || page < 1) { | ||
page = 1; | ||
} | ||
if (!size || size < 1) { | ||
size = 5; | ||
} | ||
|
||
const hasPrevious = page > 1; | ||
const hasNext = page * size < total; | ||
const totalPages = Math.ceil(total / size); | ||
const isLast = page === totalPages; | ||
const isFirst = page === 1; | ||
return { | ||
data, | ||
hasPrevious, | ||
hasNext, | ||
totalPages, | ||
isLast, | ||
isFirst, | ||
}; | ||
} | ||
|
||
export { pagination, returnablePaginated }; |
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,19 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsNotEmpty, IsNumber, IsString } from 'class-validator'; | ||
|
||
export class RatingCreateDto { | ||
@ApiProperty() | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly userId: string; | ||
|
||
@ApiProperty() | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly givenByUserId: string; | ||
|
||
@ApiProperty() | ||
@IsNotEmpty() | ||
@IsNumber() | ||
readonly ratingOf10: number; | ||
} |
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,24 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsNotEmpty, IsNumber, IsString } from 'class-validator'; | ||
|
||
export class RatingUpdateDto { | ||
@ApiProperty() | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly id: string; | ||
|
||
@ApiProperty() | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly userId: string; | ||
|
||
@ApiProperty() | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly givenByUserId: string; | ||
|
||
@ApiProperty() | ||
@IsNotEmpty() | ||
@IsNumber() | ||
readonly ratingOf10?: number; | ||
} |
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,5 @@ | ||
export interface IRating { | ||
id: string; | ||
givenByUserId: string; | ||
ratingOf10?: number; | ||
} |
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,53 @@ | ||
import { | ||
Body, | ||
Controller, | ||
HttpStatus, | ||
Post, | ||
Res, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; | ||
import { RatingService } from './rating.service'; | ||
import { RatingCreateDto } from './dto/rating-create.dto'; | ||
import { Roles } from '../auth/roles/role.decorator'; | ||
import { JwtAuthGuard } from '../auth/jwt/jwt-auth.guard'; | ||
import { RoleGuard } from '../auth/roles/role.guard'; | ||
import { Role } from '../auth/roles/role.enum'; | ||
import { RatingUpdateDto } from './dto/rating-update.dto'; | ||
|
||
@ApiTags('Rating') | ||
@Controller('rating') | ||
export class RatingController { | ||
constructor(private ratingService: RatingService) {} | ||
|
||
@ApiBearerAuth() | ||
@Roles(Role.USER) | ||
@UseGuards(JwtAuthGuard, RoleGuard) | ||
@Post('create') | ||
async createRating(@Res() res, @Body() data: RatingCreateDto) { | ||
try { | ||
console.log( | ||
`#createRating request incoming with res: ${res} and data: ${data}`, | ||
); | ||
const response = await this.ratingService.create(data); | ||
return res.status(HttpStatus.OK).json({ response }); | ||
} catch (error) { | ||
console.error('#createJob error caused by: ', error); | ||
return res.status(error.status).json({ error: error.message }); | ||
} | ||
} | ||
|
||
@ApiBearerAuth() | ||
@Roles(Role.USER) | ||
@UseGuards(JwtAuthGuard, RoleGuard) | ||
@Post('update') | ||
async updateRating(@Res() res, @Body() data: RatingUpdateDto) { | ||
try { | ||
const response = await this.ratingService.update(data); | ||
return res.status(HttpStatus.OK).json({ response }); | ||
} catch (error) { | ||
console.error('#updateJob error caused by: ', error); | ||
return res.status(error.status).json({ error: error.message }); | ||
} | ||
} | ||
} |
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,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { RatingService } from './rating.service'; | ||
import { PrismaService } from '../prisma/prisma.service'; | ||
import { RatingController } from './rating.controller'; | ||
import { RatingRepository } from './rating.repository'; | ||
|
||
@Module({ | ||
providers: [RatingService, PrismaService, RatingRepository], | ||
exports: [RatingService], | ||
controllers: [RatingController], | ||
}) | ||
export class RatingModule {} |
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,27 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { PrismaService } from '../prisma/prisma.service'; | ||
import { RatingCreateDto } from './dto/rating-create.dto'; | ||
|
||
@Injectable() | ||
export class RatingRepository { | ||
public model; | ||
|
||
constructor(private prisma: PrismaService) { | ||
this.model = this.prisma.rating; | ||
} | ||
|
||
async create(rating: RatingCreateDto): Promise<any> { | ||
return this.prisma.rating.create({ | ||
data: rating, | ||
}); | ||
} | ||
|
||
async update(ratingId: string, data: any): Promise<any> { | ||
return this.prisma.rating.update({ | ||
where: { | ||
id: ratingId, | ||
}, | ||
data, | ||
}); | ||
} | ||
} |
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,19 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { RatingRepository } from './rating.repository'; | ||
import { IRating } from './interface/rating.interface'; | ||
import { RatingCreateDto } from './dto/rating-create.dto'; | ||
import { RatingUpdateDto } from './dto/rating-update.dto'; | ||
|
||
@Injectable() | ||
export class RatingService { | ||
constructor(private ratingRepository: RatingRepository) {} | ||
|
||
async create(rating: RatingCreateDto): Promise<IRating> { | ||
return this.ratingRepository.create(rating); | ||
} | ||
|
||
async update(rating: RatingUpdateDto): Promise<IRating> { | ||
const { id, ...data } = rating; | ||
return this.ratingRepository.update(id, data); | ||
} | ||
} |
Oops, something went wrong.