Skip to content

Commit

Permalink
Merge pull request #51 from richard483/fix-1
Browse files Browse the repository at this point in the history
Fix 1
  • Loading branch information
richard483 authored Jan 13, 2024
2 parents a4090f4 + f451a16 commit c8ffae8
Show file tree
Hide file tree
Showing 31 changed files with 139 additions and 96 deletions.
2 changes: 1 addition & 1 deletion docs/auth-controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ HTTP Code: 200
"previousWorkplaceCount": null,
"ratingsAvg": null,
"companyId": null,
"portofolio": [],
"portfolio": [],
"profilePicture": null,
"hasGoogleAccount": false
}
Expand Down
8 changes: 4 additions & 4 deletions docs/user-controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
| `description` | String |
| `previousWorkPlace` | String[] |
| `companyId` | String |
| `portofolio` | String[] |
| `portfolio` | String[] |
| `profilePicture` | String |

### Success Response
Expand Down Expand Up @@ -54,7 +54,7 @@ HTTP Code: 200
"previousWorkplaceCount": 3,
"ratingsAvg": null,
"companyId": null,
"portofolio": [],
"portfolio": [],
"profilePicture": "https://www.google.com/url?sa=i&url=https%3A%2F%2Fgithub.com%2Fnestjs%2Fswagger%2Fissues%2F1062&psig=AOvVaw3aa3sM4HwPBnbxa_JISyrs&ust=1704354787503000&source=images&cd=vfe&opi=89978449&ved=0CBEQjRxqFwoTCKDOkcfewIMDFQAAAAAdAAAAABAD",
"hasGoogleAccount": false
}
Expand Down Expand Up @@ -164,7 +164,7 @@ HTTP Code: 200
"previousWorkplaceCount": 3,
"ratingsAvg": null,
"companyId": null,
"portofolio": [],
"portfolio": [],
"profilePicture": "https://firebasestorage.googleapis.com/v0/b/tech-395620.appspot.com/o/profilePicture%2Fd29636a9-ecdd-4905-9568-27e0af35732f.jpg?alt=media&token=25968c38-961d-41f2-be7e-2262ee44e142",
"hasGoogleAccount": false
}
Expand Down Expand Up @@ -220,7 +220,7 @@ HTTP Code: 200
"previousWorkplaceCount": 0,
"ratingsAvg": null,
"companyId": null,
"portofolio": [],
"portfolio": [],
"profilePicture": null,
"hasGoogleAccount": false
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backend-8tech",
"version": "4.0.2",
"version": "4.0.3",
"description": "",
"author": "8tech",
"private": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Warnings:
- You are about to drop the column `givenByUserId` on the `Rating` table. All the data in the column will be lost.
- You are about to drop the column `portofolio` on the `User` table. All the data in the column will be lost.
- Added the required column `recruiterUserId` to the `Rating` table without a default value. This is not possible if the table is not empty.
- Added the required column `updatedAt` to the `Rating` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Rating" DROP COLUMN "givenByUserId",
ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "recruiterUserId" TEXT NOT NULL,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL;

-- AlterTable
ALTER TABLE "User" DROP COLUMN "portofolio",
ADD COLUMN "portfolio" TEXT[];
14 changes: 8 additions & 6 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ model User {
ratings Rating[]
ratingsAvg Float?
companyId String?
portofolio String[]
portfolio String[] @map("portfolio")
profilePicture String?
hasGoogleAccount Boolean @default(false)
company Company? @relation(fields: [companyId], references: [id])
Expand Down Expand Up @@ -88,11 +88,13 @@ model Payment {
}

model Rating {
id String @id @default(uuid())
User User @relation(fields: [userId], references: [id])
userId String
givenByUserId String
ratingOf10 Int
id String @id @default(uuid())
User User @relation(fields: [userId], references: [id])
userId String
recruiterUserId String
ratingOf10 Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

enum Role {
Expand Down
8 changes: 4 additions & 4 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ import { AuthService } from './auth.service';
import { ApiBearerAuth, ApiCookieAuth, ApiTags } from '@nestjs/swagger';
import { Roles } from './roles/role.decorator';
import { Role } from './roles/role.enum';
import { AuthenticateRequest } from './requests/authenticate.request';
import { AuthenticateRequestDto } from './dto/authenticate.dto';
import { JwtAuthGuard } from './jwt/jwt-auth.guard';
import { RoleGuard } from './roles/role.guard';
import { GoogleGuard } from './google/google.guard';
import { RegisterRequest } from './requests/register.request';
import { RegisterRequestDto } from './dto/register.dto';

@ApiTags('Auth')
@Controller('auth')
export class AuthController {
constructor(private authService: AuthService) {}

@Post('login')
async signIn(@Res() res, @Body() authenticateDto: AuthenticateRequest) {
async signIn(@Res() res, @Body() authenticateDto: AuthenticateRequestDto) {
console.info('#AuthLogin request incoming with: ', authenticateDto);
const response = await this.authService.login(authenticateDto, res);
return response;
}

@Post('register')
async signUp(@Res() res, @Body() request: RegisterRequest) {
async signUp(@Res() res, @Body() request: RegisterRequestDto) {
console.info('#AuthRegister request incoming with: ', request);
const response = await this.authService.register(request);
return response;
Expand Down
10 changes: 5 additions & 5 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { UsersService } from '../users/users.service';
import { AuthenticateRequest } from './requests/authenticate.request';
import { AuthenticateRequestDto } from './dto/authenticate.dto';
import { IAuthenticate, IGoogleUser } from './interface/auth.interface';
import { IUser } from '../users/interface/user.interface';
import { compare, genSaltSync, hashSync } from 'bcrypt';
import { RegisterRequest } from './requests/register.request';
import { RegisterRequestDto } from './dto/register.dto';
import { Role } from '@prisma/client';

@Injectable()
Expand All @@ -16,7 +16,7 @@ export class AuthService {
) {}

async validateUser(
authenticateRequest: AuthenticateRequest,
authenticateRequest: AuthenticateRequestDto,
): Promise<IAuthenticate> {
const user = await this.usersService.findOne(authenticateRequest.email);
if (!user) {
Expand All @@ -42,15 +42,15 @@ export class AuthService {
}

async login(
authenticateRequest: AuthenticateRequest,
authenticateRequest: AuthenticateRequestDto,
res,
): Promise<IAuthenticate> {
const user = await this.validateUser(authenticateRequest);
user.token = this.jwtService.sign(user);
return user;
}

async register(request: RegisterRequest): Promise<IUser> {
async register(request: RegisterRequestDto): Promise<IUser> {
let data;
const { isRecruiter, ...userCreate } = request;
if (isRecruiter) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';

export class AuthenticateRequest {
export class AuthenticateRequestDto {
@ApiProperty()
@IsNotEmpty()
@IsEmail()
@IsEmail(
{
allow_display_name: false,
},
{
message: 'INVALID_EMAIL',
},
)
readonly email: string;

@ApiProperty()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsOptional, Matches } from 'class-validator';

export class RegisterRequest {
export class RegisterRequestDto {
@ApiProperty()
@IsNotEmpty({
message: 'MUST_NOT_BE_EMPTY',
Expand Down
4 changes: 2 additions & 2 deletions src/auth/test/auth.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const mockIAuthSuccessResponse: IAuthenticate = {
roles: ['MEMBER'],
hasGoogleAccount: false,
description: 'desc',
portofolio: [],
portfolio: [],
},
token: 'token',
};
Expand All @@ -42,7 +42,7 @@ const mockIUserResponse: IUser = {
roles: ['MEMBER'],
hasGoogleAccount: false,
description: 'desc',
portofolio: [],
portfolio: [],
};

describe('AuthController', () => {
Expand Down
14 changes: 7 additions & 7 deletions src/contract/contract.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class ContractController {
return response;
}

//9432dae7-ba04-410a-a4ff-27d6da87ae63
@Get('generate/:contractId')
@ApiParam({ name: 'contractId', type: String })
@Roles(Role.USER)
Expand Down Expand Up @@ -72,8 +71,9 @@ export class ContractController {
@ApiParam({ name: 'userId', type: String })
async getAllbyUserId(@Res() res, @Param('userId') userId: string) {
console.info('#getAllbyUserId request incoming with: ', userId);
const response: Contract[] =
await this.contractService.getAllbyUserId(userId);
const response: Contract[] = await this.contractService.getAllbyUserId(
userId,
);
return response;
}

Expand All @@ -82,8 +82,9 @@ export class ContractController {
@ApiParam({ name: 'jobId', type: String })
async getAllbyJobId(@Res() res, @Param('jobId') jobId: string) {
console.info('#getAllbyJobId request incoming with: ', jobId);
const response: Contract[] =
await this.contractService.getAllbyJobId(jobId);
const response: Contract[] = await this.contractService.getAllbyJobId(
jobId,
);
return response;
}

Expand All @@ -92,8 +93,7 @@ export class ContractController {
@ApiParam({ name: 'Id', type: String })
async getContractbyId(@Res() res, @Param('Id') Id: string) {
console.info('#getContractbyId request incoming with: ', Id);
const response: Contract =
await this.contractService.getContractbyId(Id);
const response: Contract = await this.contractService.getContractbyId(Id);
return response;
}

Expand Down
4 changes: 2 additions & 2 deletions src/contract/contract.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export class ContractRepository {
});
}

async getAllbyUserId(userId : string): Promise<Contract[]> {
async getAllbyUserId(userId: string): Promise<Contract[]> {
return this.prisma.contract.findMany({
where: {
userId,
},
});
}

async getAllbyJobId(jobId : string): Promise<Contract[]> {
async getAllbyJobId(jobId: string): Promise<Contract[]> {
return this.prisma.contract.findMany({
where: {
jobId,
Expand Down
6 changes: 3 additions & 3 deletions src/contract/contract.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ export class ContractService {
}

//GetAll Contract by userId
async getAllbyUserId(userId : string): Promise<Contract[]> {
async getAllbyUserId(userId: string): Promise<Contract[]> {
return await this.contractRepository.getAllbyUserId(userId);
}

//GetAll Contract by jobId
async getAllbyJobId(jobId : string): Promise<Contract[]> {
async getAllbyJobId(jobId: string): Promise<Contract[]> {
return await this.contractRepository.getAllbyJobId(jobId);
}

//Get Contract by contractId
async getContractbyId(id : string): Promise<Contract>{
async getContractbyId(id: string): Promise<Contract> {
return await this.contractRepository.get(id);
}

Expand Down
2 changes: 1 addition & 1 deletion src/interceptors/response.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class ResponseInterceptor implements NestInterceptor {
'#responseHandler: trying to set cookie for this response: ',
res,
);
if (res != undefined) {
if (res != undefined && res?.token != undefined) {
response.cookie('EToken', res?.token);
console.log(
'#responseHandler: success to set cookie for this response: ',
Expand Down
8 changes: 0 additions & 8 deletions src/job/interface/job.interface.ts

This file was deleted.

10 changes: 5 additions & 5 deletions src/job/test/job.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { JwtAuthGuard } from '../../auth/jwt/jwt-auth.guard';
import { RoleGuard } from '../../auth/roles/role.guard';
import { JobController } from '../job.controller';
import { JobService } from '../job.service';
import { IJob } from '../interface/job.interface';
import { JobVacancy } from '@prisma/client';

describe('JobController', () => {
let controller: JobController;
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('JobController', () => {
companyId: 'test',
};

const mockJob: IJob = {
const mockJob: JobVacancy = {
id: 'randomId',
title: 'deez noot',
description: 'this is description about job that is created for test',
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('JobController', () => {
});

it('deleteJob success', async () => {
const mockJob: IJob = {
const mockJob: JobVacancy = {
id: 'randomId',
title: 'deez noot',
description: 'this is description about job that is created for test',
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('JobController', () => {
}
});
it('updateJob success', async () => {
const mockJob: IJob = {
const mockJob: JobVacancy = {
id: 'randomId',
title: 'deez noot',
description: 'this is description about job that is created for test',
Expand Down Expand Up @@ -224,7 +224,7 @@ describe('JobController', () => {
}
});
it('getJob success', async () => {
const mockJob: IJob = {
const mockJob: JobVacancy = {
id: 'randomId',
title: 'deez noot',
description: 'this is description about job that is created for test',
Expand Down
4 changes: 2 additions & 2 deletions src/job/test/job.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Test, TestingModule } from '@nestjs/testing';
import { DeepMocked, createMock } from '@golevelup/ts-jest';
import { JobService } from '../job.service';
import { IJob } from '../interface/job.interface';
import { JobRepository } from '../job.repository';
import { JobUpdateDto } from '../dto/job-update.dto';
import { JobVacancy } from '@prisma/client';

describe('JobService', () => {
let service: JobService;
let reposiotry: DeepMocked<JobRepository>;
let jobMock: IJob;
let jobMock: JobVacancy;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
Expand Down
Loading

0 comments on commit c8ffae8

Please sign in to comment.