feat: update field

This commit is contained in:
Methapon2001 2024-06-11 11:27:00 +07:00
parent c079f43e8d
commit af4489dccc
7 changed files with 162 additions and 160 deletions

View file

@ -0,0 +1,31 @@
-- AlterTable
ALTER TABLE "EmployeeCheckup" ALTER COLUMN "checkupResult" DROP NOT NULL,
ALTER COLUMN "checkupType" DROP NOT NULL,
ALTER COLUMN "hospitalName" DROP NOT NULL,
ALTER COLUMN "remark" DROP NOT NULL,
ALTER COLUMN "medicalBenefitScheme" DROP NOT NULL,
ALTER COLUMN "insuranceCompany" DROP NOT NULL,
ALTER COLUMN "coverageStartDate" DROP NOT NULL,
ALTER COLUMN "coverageExpireDate" DROP NOT NULL;
-- AlterTable
ALTER TABLE "EmployeeOtherInfo" ALTER COLUMN "citizenId" DROP NOT NULL,
ALTER COLUMN "fatherFirstName" DROP NOT NULL,
ALTER COLUMN "fatherFirstNameEN" DROP NOT NULL,
ALTER COLUMN "fatherLastName" DROP NOT NULL,
ALTER COLUMN "fatherLastNameEN" DROP NOT NULL,
ALTER COLUMN "motherFirstName" DROP NOT NULL,
ALTER COLUMN "motherFirstNameEN" DROP NOT NULL,
ALTER COLUMN "motherLastName" DROP NOT NULL,
ALTER COLUMN "motherLastNameEN" DROP NOT NULL,
ALTER COLUMN "birthPlace" DROP NOT NULL;
-- AlterTable
ALTER TABLE "EmployeeWork" ALTER COLUMN "ownerName" DROP NOT NULL,
ALTER COLUMN "positionName" DROP NOT NULL,
ALTER COLUMN "jobType" DROP NOT NULL,
ALTER COLUMN "workplace" DROP NOT NULL,
ALTER COLUMN "workPermitNo" DROP NOT NULL,
ALTER COLUMN "workPermitIssuDate" DROP NOT NULL,
ALTER COLUMN "workPermitExpireDate" DROP NOT NULL,
ALTER COLUMN "workEndDate" DROP NOT NULL;

View file

@ -0,0 +1,10 @@
/*
Warnings:
- You are about to drop the column `birthPlace` on the `EmployeeOtherInfo` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "EmployeeOtherInfo" DROP COLUMN "birthPlace",
ADD COLUMN "fatherBirthPlace" TEXT,
ADD COLUMN "motherBirthPlace" TEXT;

View file

@ -467,18 +467,18 @@ model EmployeeCheckup {
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade) employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
employeeId String employeeId String
checkupResult String checkupResult String?
checkupType String checkupType String?
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull) province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String? provinceId String?
hospitalName String hospitalName String?
remark String remark String?
medicalBenefitScheme String medicalBenefitScheme String?
insuranceCompany String insuranceCompany String?
coverageStartDate DateTime coverageStartDate DateTime?
coverageExpireDate DateTime coverageExpireDate DateTime?
createdBy String? createdBy String?
createdAt DateTime @default(now()) createdAt DateTime @default(now())
@ -492,14 +492,14 @@ model EmployeeWork {
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade) employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
employeeId String employeeId String
ownerName String ownerName String?
positionName String positionName String?
jobType String jobType String?
workplace String workplace String?
workPermitNo String workPermitNo String?
workPermitIssuDate DateTime workPermitIssuDate DateTime?
workPermitExpireDate DateTime workPermitExpireDate DateTime?
workEndDate DateTime workEndDate DateTime?
remark String? remark String?
createdBy String? createdBy String?
@ -514,17 +514,18 @@ model EmployeeOtherInfo {
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade) employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
employeeId String employeeId String
citizenId String citizenId String?
birthPlace String fatherBirthPlace String?
fatherFirstName String fatherFirstName String?
fatherLastName String fatherLastName String?
motherFirstName String motherBirthPlace String?
motherLastName String motherFirstName String?
motherLastName String?
fatherFirstNameEN String fatherFirstNameEN String?
fatherLastNameEN String fatherLastNameEN String?
motherFirstNameEN String motherFirstNameEN String?
motherLastNameEN String motherLastNameEN String?
createdBy String? createdBy String?
createdAt DateTime @default(now()) createdAt DateTime @default(now())

View file

@ -16,32 +16,18 @@ import prisma from "../db";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
type EmployeeCheckupCreate = { type EmployeeCheckupPayload = {
checkupType: string; checkupType?: string | null;
checkupResult: string; checkupResult?: string | null;
provinceId?: string | null; provinceId?: string | null;
hospitalName: string; hospitalName?: string | null;
remark: string; remark?: string | null;
medicalBenefitScheme: string; medicalBenefitScheme?: string | null;
insuranceCompany: string; insuranceCompany?: string | null;
coverageStartDate: Date; coverageStartDate?: Date | null;
coverageExpireDate: Date; coverageExpireDate?: Date | null;
};
type EmployeeCheckupEdit = {
checkupType?: string;
checkupResult?: string;
provinceId?: string | null;
hospitalName?: string;
remark?: string;
medicalBenefitScheme?: string;
insuranceCompany?: string;
coverageStartDate?: Date;
coverageExpireDate?: Date;
}; };
@Route("api/v1/employee/{employeeId}/checkup") @Route("api/v1/employee/{employeeId}/checkup")
@ -75,7 +61,7 @@ export class EmployeeCheckupController extends Controller {
async create( async create(
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() employeeId: string, @Path() employeeId: string,
@Body() body: EmployeeCheckupCreate, @Body() body: EmployeeCheckupPayload,
) { ) {
if (body.provinceId || employeeId) { if (body.provinceId || employeeId) {
const [province, employee] = await prisma.$transaction([ const [province, employee] = await prisma.$transaction([
@ -119,7 +105,7 @@ export class EmployeeCheckupController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() employeeId: string, @Path() employeeId: string,
@Path() checkupId: string, @Path() checkupId: string,
@Body() body: EmployeeCheckupEdit, @Body() body: EmployeeCheckupPayload,
) { ) {
if (body.provinceId || employeeId) { if (body.provinceId || employeeId) {
const [province, employee] = await prisma.$transaction([ const [province, employee] = await prisma.$transaction([

View file

@ -26,7 +26,7 @@ if (!process.env.MINIO_BUCKET) {
const MINIO_BUCKET = process.env.MINIO_BUCKET; const MINIO_BUCKET = process.env.MINIO_BUCKET;
function imageLocation(id: string) { function imageLocation(id: string) {
return `employee/profile-img-${id}`; return `employee/${id}/profile-image`;
} }
type EmployeeCreate = { type EmployeeCreate = {
@ -72,43 +72,43 @@ type EmployeeCreate = {
provinceId?: string | null; provinceId?: string | null;
employeeWork?: { employeeWork?: {
ownerName: string; ownerName?: string | null;
positionName: string; positionName?: string | null;
jobType: string; jobType?: string | null;
workplace: string; workplace?: string | null;
workPermitNo: string; workPermitNo?: string | null;
workPermitIssuDate: Date; workPermitIssuDate?: Date | null;
workPermitExpireDate: Date; workPermitExpireDate?: Date | null;
workEndDate: Date; workEndDate?: Date | null;
remark?: string; remark?: string | null;
}[]; }[];
employeeCheckup?: { employeeCheckup?: {
checkupType: string; checkupType?: string | null;
checkupResult: string; checkupResult?: string | null;
provinceId?: string | null; provinceId?: string | null;
hospitalName: string; hospitalName?: string | null;
remark: string; remark?: string | null;
medicalBenefitScheme: string; medicalBenefitScheme?: string | null;
insuranceCompany: string; insuranceCompany?: string | null;
coverageStartDate: Date; coverageStartDate?: Date | null;
coverageExpireDate: Date; coverageExpireDate?: Date | null;
}[]; }[];
employeeOtherInfo: { employeeOtherInfo?: {
citizenId: string; citizenId?: string | null;
fatherFirstName: string; fatherFirstName?: string | null;
fatherLastName: string; fatherLastName?: string | null;
motherFirstName: string; motherFirstName?: string | null;
motherLastName: string; motherLastName?: string | null;
fatherFirstNameEN: string; fatherFirstNameEN?: string | null;
fatherLastNameEN: string; fatherLastNameEN?: string | null;
motherFirstNameEN: string; motherFirstNameEN?: string | null;
motherLastNameEN: string; motherLastNameEN?: string | null;
birthPlace: string; birthPlace?: string | null;
}; };
}; };
@ -155,44 +155,45 @@ type EmployeeUpdate = {
employeeWork?: { employeeWork?: {
id?: string; id?: string;
ownerName: string; ownerName?: string | null;
positionName: string; positionName?: string | null;
jobType: string; jobType?: string | null;
workplace: string; workplace?: string | null;
workPermitNo: string; workPermitNo?: string | null;
workPermitIssuDate: Date; workPermitIssuDate?: Date | null;
workPermitExpireDate: Date; workPermitExpireDate?: Date | null;
workEndDate: Date; workEndDate?: Date | null;
remark?: string; remark?: string | null;
}[]; }[];
employeeCheckup?: { employeeCheckup?: {
id?: string; id?: string;
checkupType: string; checkupType?: string | null;
checkupResult: string; checkupResult?: string | null;
provinceId?: string | null; provinceId?: string | null;
hospitalName: string; hospitalName?: string | null;
remark: string; remark?: string | null;
medicalBenefitScheme: string; medicalBenefitScheme?: string | null;
insuranceCompany: string; insuranceCompany?: string | null;
coverageStartDate: Date; coverageStartDate?: Date | null;
coverageExpireDate: Date; coverageExpireDate?: Date | null;
}[]; }[];
employeeOtherInfo: { employeeOtherInfo: {
citizenId: string; citizenId?: string | null;
fatherFirstName: string; fatherFirstName?: string | null;
fatherLastName: string; fatherLastName?: string | null;
motherFirstName: string; fatherBirthPlace?: string | null;
motherLastName: string; motherFirstName?: string | null;
motherLastName?: string | null;
motherBirthPlace?: string | null;
fatherFirstNameEN: string; fatherFirstNameEN?: string | null;
fatherLastNameEN: string; fatherLastNameEN?: string | null;
motherFirstNameEN: string; motherFirstNameEN?: string | null;
motherLastNameEN: string; motherLastNameEN?: string | null;
birthPlace: string;
}; };
}; };

View file

@ -1,4 +1,3 @@
import { Prisma, Status } from "@prisma/client";
import { import {
Body, Body,
Controller, Controller,
@ -7,7 +6,6 @@ import {
Put, Put,
Path, Path,
Post, Post,
Query,
Request, Request,
Route, Route,
Security, Security,
@ -19,32 +17,19 @@ import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import { RequestWithUser } from "../interfaces/user"; import { RequestWithUser } from "../interfaces/user";
type EmployeeOtherInfoCreate = { type EmployeeOtherInfoPayload = {
citizenId: string; citizenId?: string | null;
fatherFirstName: string; fatherFirstName?: string | null;
fatherLastName: string; fatherLastName?: string | null;
motherFirstName: string; fatherBirthPlace?: string | null;
motherLastName: string; motherFirstName?: string | null;
motherLastName?: string | null;
motherBirthPlace?: string | null;
fatherFirstNameEN: string; fatherFirstNameEN?: string | null;
fatherLastNameEN: string; fatherLastNameEN?: string | null;
motherFirstNameEN: string; motherFirstNameEN?: string | null;
motherLastNameEN: string; motherLastNameEN?: string | null;
birthPlace: string;
};
type EmployeeOtherInfoUpdate = {
citizenId: string;
fatherFirstName: string;
fatherLastName: string;
motherFirstName: string;
motherLastName: string;
fatherFirstNameEN: string;
fatherLastNameEN: string;
motherFirstNameEN: string;
motherLastNameEN: string;
birthPlace: string;
}; };
@Route("api/v1/employee/{employeeId}/other-info") @Route("api/v1/employee/{employeeId}/other-info")
@ -74,7 +59,7 @@ export class EmployeeOtherInfo extends Controller {
async create( async create(
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() employeeId: string, @Path() employeeId: string,
@Body() body: EmployeeOtherInfoCreate, @Body() body: EmployeeOtherInfoPayload,
) { ) {
if (!(await prisma.employee.findUnique({ where: { id: employeeId } }))) if (!(await prisma.employee.findUnique({ where: { id: employeeId } })))
throw new HttpError( throw new HttpError(
@ -102,7 +87,7 @@ export class EmployeeOtherInfo extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() employeeId: string, @Path() employeeId: string,
@Path() otherInfoId: string, @Path() otherInfoId: string,
@Body() body: EmployeeOtherInfoUpdate, @Body() body: EmployeeOtherInfoPayload,
) { ) {
if (!(await prisma.employeeOtherInfo.findUnique({ where: { id: otherInfoId, employeeId } }))) { if (!(await prisma.employeeOtherInfo.findUnique({ where: { id: otherInfoId, employeeId } }))) {
throw new HttpError( throw new HttpError(

View file

@ -16,28 +16,16 @@ import prisma from "../db";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
type EmployeeWorkCreate = { type EmployeeWorkPayload = {
ownerName: string; ownerName?: string | null;
positionName: string; positionName?: string | null;
jobType: string; jobType?: string | null;
workplace: string; workplace?: string | null;
workPermitNo: string; workPermitNo?: string | null;
workPermitIssuDate: Date; workPermitIssuDate?: Date | null;
workPermitExpireDate: Date; workPermitExpireDate?: Date | null;
workEndDate: Date; workEndDate?: Date | null;
remark?: string; remark?: string | null;
};
type EmployeeWorkUpdate = {
ownerName?: string;
positionName?: string;
jobType?: string;
workplace?: string;
workPermitNo?: string;
workPermitIssuDate?: Date;
workPermitExpireDate?: Date;
workEndDate?: Date;
remark?: string;
}; };
@Route("api/v1/employee/{employeeId}/work") @Route("api/v1/employee/{employeeId}/work")
@ -67,7 +55,7 @@ export class EmployeeWorkController extends Controller {
async create( async create(
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() employeeId: string, @Path() employeeId: string,
@Body() body: EmployeeWorkCreate, @Body() body: EmployeeWorkPayload,
) { ) {
if (!(await prisma.employee.findUnique({ where: { id: employeeId } }))) if (!(await prisma.employee.findUnique({ where: { id: employeeId } })))
throw new HttpError( throw new HttpError(
@ -95,7 +83,7 @@ export class EmployeeWorkController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() employeeId: string, @Path() employeeId: string,
@Path() workId: string, @Path() workId: string,
@Body() body: EmployeeWorkUpdate, @Body() body: EmployeeWorkPayload,
) { ) {
if (!(await prisma.employeeWork.findUnique({ where: { id: workId, employeeId } }))) { if (!(await prisma.employeeWork.findUnique({ where: { id: workId, employeeId } }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "Employee work cannot be found.", "data_not_found"); throw new HttpError(HttpStatus.NOT_FOUND, "Employee work cannot be found.", "data_not_found");