-
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 #15 from richard483/feature/job-crud
Feature/job crud
- Loading branch information
Showing
25 changed files
with
2,570 additions
and
1,208 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,47 @@ | ||
-- AlterTable | ||
ALTER TABLE "User" ADD COLUMN "hasGoogleAccount" BOOLEAN NOT NULL DEFAULT false, | ||
ALTER COLUMN "password" DROP NOT NULL, | ||
ALTER COLUMN "roles" SET DEFAULT ARRAY['USER']::"Role"[]; | ||
|
||
-- CreateTable | ||
CREATE TABLE "JobVacancy" ( | ||
"id" TEXT NOT NULL, | ||
"title" TEXT NOT NULL, | ||
"description" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
"companyId" TEXT NOT NULL, | ||
|
||
CONSTRAINT "JobVacancy_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Company" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"description" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "Company_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Contract" ( | ||
"id" TEXT NOT NULL, | ||
"userId" TEXT NOT NULL, | ||
"jobId" TEXT NOT NULL, | ||
"title" TEXT NOT NULL, | ||
"description" TEXT NOT NULL, | ||
"template" VARCHAR NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "Contract_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "JobVacancy" ADD CONSTRAINT "JobVacancy_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "Company"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Contract" ADD CONSTRAINT "Contract_jobId_fkey" FOREIGN KEY ("jobId") REFERENCES "JobVacancy"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
8 changes: 8 additions & 0 deletions
8
...231010154119_opitonalize_company_id_on_job_vacancy_for_development_purposes/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 @@ | ||
-- DropForeignKey | ||
ALTER TABLE "JobVacancy" DROP CONSTRAINT "JobVacancy_companyId_fkey"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "JobVacancy" ALTER COLUMN "companyId" DROP NOT NULL; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "JobVacancy" ADD CONSTRAINT "JobVacancy_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
import { genSaltSync, hashSync } from 'bcrypt'; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
function hashPassword(password: string) { | ||
const salt = genSaltSync(10); | ||
const hashedPassword = hashSync(password, salt); | ||
return hashedPassword; | ||
} | ||
async function main() { | ||
const admin = await prisma.user.upsert({ | ||
where: { email: 'admin@email.com' }, | ||
update: {}, | ||
create: { | ||
email: 'admin@email.com', | ||
userName: 'Admin', | ||
password: hashPassword('Admin123_'), | ||
roles: ['ADMIN', 'USER'], | ||
}, | ||
}); | ||
|
||
const defaultUser = await prisma.user.upsert({ | ||
where: { email: 'default.user@email.com' }, | ||
update: {}, | ||
create: { | ||
email: 'default.user@email.com', | ||
userName: 'Default User', | ||
password: hashPassword('User123_'), | ||
roles: ['USER'], | ||
}, | ||
}); | ||
console.log({ admin, defaultUser }); | ||
} | ||
|
||
main() | ||
.then(async () => { | ||
await prisma.$disconnect(); | ||
}) | ||
.catch(async (e) => { | ||
console.error(e); | ||
await prisma.$disconnect(); | ||
process.exit(1); | ||
}); |
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,34 @@ | ||
import { | ||
Body, | ||
Controller, | ||
HttpStatus, | ||
Post, | ||
Res, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; | ||
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 { ContractService } from './contract.service'; | ||
import { ContractCreateDto } from './dto/contract-create.dto'; | ||
|
||
@ApiTags('Contract') | ||
@Controller('contract') | ||
export class ContractController { | ||
constructor(private contractService: ContractService) {} | ||
|
||
@ApiBearerAuth() | ||
@Roles(Role.USER) | ||
@UseGuards(JwtAuthGuard, RoleGuard) | ||
@Post('create') | ||
async createContract(@Res() res, @Body() contract: ContractCreateDto) { | ||
try { | ||
const response = await this.contractService.create(contract); | ||
return res.status(HttpStatus.OK).json({ response }); | ||
} catch (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 { PrismaService } from '../prisma/prisma.service'; | ||
import { ContractService } from './contract.service'; | ||
import { ContractRepository } from './contract.repository'; | ||
import { ContractController } from './contract.controller'; | ||
|
||
@Module({ | ||
providers: [ContractService, PrismaService, ContractRepository], | ||
exports: [ContractService], | ||
controllers: [ContractController], | ||
}) | ||
export class ContractModule {} |
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,17 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { PrismaService } from '../prisma/prisma.service'; | ||
|
||
@Injectable() | ||
export class ContractRepository { | ||
public model; | ||
|
||
constructor(private prisma: PrismaService) { | ||
this.model = this.prisma.contract; | ||
} | ||
|
||
async create(contract: any): Promise<any> { | ||
return this.prisma.contract.create({ | ||
data: contract, | ||
}); | ||
} | ||
} |
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 { Injectable } from '@nestjs/common'; | ||
import { ContractRepository } from './contract.repository'; | ||
import { IContract } from './interface/contract.interface'; | ||
|
||
@Injectable() | ||
export class ContractService { | ||
constructor(private contractRepository: ContractRepository) {} | ||
|
||
async create(user: any): Promise<IContract> { | ||
return this.contractRepository.create(user); | ||
} | ||
} |
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 { ApiProperty } from '@nestjs/swagger'; | ||
import { IsNotEmpty, IsString } from 'class-validator'; | ||
|
||
export class ContractCreateDto { | ||
@ApiProperty() | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly userId: string; | ||
|
||
@ApiProperty() | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly jobId: string; | ||
|
||
@ApiProperty() | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly title: string; | ||
|
||
@ApiProperty() | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly description: string; | ||
|
||
@ApiProperty() | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly template: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface IContract { | ||
id: string; | ||
userId: string; | ||
jobId: string; | ||
title: string; | ||
description: string; | ||
template: string; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
} |
Oops, something went wrong.