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

View file

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

View file

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

View file

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

View file

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