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

@ -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");