refactor!: remove in country notice
This commit is contained in:
parent
68f425a149
commit
75ecf230f7
3 changed files with 5 additions and 146 deletions
|
|
@ -767,12 +767,11 @@ model Employee {
|
||||||
updatedBy User? @relation(name: "EmployeeUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
|
updatedBy User? @relation(name: "EmployeeUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
|
||||||
updatedByUserId String?
|
updatedByUserId String?
|
||||||
|
|
||||||
employeePassport EmployeePassport[]
|
employeePassport EmployeePassport[]
|
||||||
employeeVisa EmployeeVisa[]
|
employeeVisa EmployeeVisa[]
|
||||||
employeeInCountryNotice EmployeeInCountryNotice[]
|
employeeCheckup EmployeeCheckup[]
|
||||||
employeeCheckup EmployeeCheckup[]
|
employeeWork EmployeeWork[]
|
||||||
employeeWork EmployeeWork[]
|
employeeOtherInfo EmployeeOtherInfo?
|
||||||
employeeOtherInfo EmployeeOtherInfo?
|
|
||||||
|
|
||||||
editHistory EmployeeHistory[]
|
editHistory EmployeeHistory[]
|
||||||
quotationWorker QuotationWorker[]
|
quotationWorker QuotationWorker[]
|
||||||
|
|
@ -850,25 +849,6 @@ model EmployeeVisa {
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
model EmployeeInCountryNotice {
|
|
||||||
id String @id @default(cuid())
|
|
||||||
|
|
||||||
noticeNumber String
|
|
||||||
noticeDate String
|
|
||||||
nextNoticeDate DateTime @db.Date
|
|
||||||
tmNumber String
|
|
||||||
|
|
||||||
entryDate DateTime @db.Date
|
|
||||||
travelBy String
|
|
||||||
travelFrom String
|
|
||||||
|
|
||||||
employee Employee @relation(fields: [employeeId], references: [id], onDelete: Cascade)
|
|
||||||
employeeId String
|
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
|
||||||
updatedAt DateTime @updatedAt
|
|
||||||
}
|
|
||||||
|
|
||||||
model EmployeeCheckup {
|
model EmployeeCheckup {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -365,7 +365,6 @@ export class EmployeeController extends Controller {
|
||||||
include: {
|
include: {
|
||||||
employeePassport: true,
|
employeePassport: true,
|
||||||
employeeVisa: true,
|
employeeVisa: true,
|
||||||
employeeInCountryNotice: true,
|
|
||||||
employeeWork: true,
|
employeeWork: true,
|
||||||
employeeCheckup: true,
|
employeeCheckup: true,
|
||||||
employeeOtherInfo: true,
|
employeeOtherInfo: true,
|
||||||
|
|
@ -639,7 +638,6 @@ export class EmployeeController extends Controller {
|
||||||
deleteFolder(fileLocation.employee.attachment(employeeId)),
|
deleteFolder(fileLocation.employee.attachment(employeeId)),
|
||||||
deleteFolder(fileLocation.employee.passport(employeeId)),
|
deleteFolder(fileLocation.employee.passport(employeeId)),
|
||||||
deleteFolder(fileLocation.employee.visa(employeeId)),
|
deleteFolder(fileLocation.employee.visa(employeeId)),
|
||||||
deleteFolder(fileLocation.employee.inCountryNotice(employeeId)),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return await prisma.employee.delete({
|
return await prisma.employee.delete({
|
||||||
|
|
|
||||||
|
|
@ -1,119 +0,0 @@
|
||||||
import {
|
|
||||||
Body,
|
|
||||||
Controller,
|
|
||||||
Delete,
|
|
||||||
Get,
|
|
||||||
Middlewares,
|
|
||||||
Path,
|
|
||||||
Post,
|
|
||||||
Put,
|
|
||||||
Route,
|
|
||||||
Security,
|
|
||||||
Tags,
|
|
||||||
} from "tsoa";
|
|
||||||
import { RequestWithUser } from "../interfaces/user";
|
|
||||||
import prisma from "../db";
|
|
||||||
import HttpStatus from "../interfaces/http-status";
|
|
||||||
import { permissionCheck } from "../middlewares/employee";
|
|
||||||
import { notFoundError } from "../utils/error";
|
|
||||||
import { deleteFile, fileLocation } from "../utils/minio";
|
|
||||||
|
|
||||||
const MANAGE_ROLES = [
|
|
||||||
"system",
|
|
||||||
"head_of_admin",
|
|
||||||
"admin",
|
|
||||||
"head_of_account",
|
|
||||||
"account",
|
|
||||||
"head_of_sale",
|
|
||||||
];
|
|
||||||
|
|
||||||
function globalAllow(user: RequestWithUser["user"]) {
|
|
||||||
const allowList = ["system", "head_of_admin", "head_of_account", "head_of_sale"];
|
|
||||||
return allowList.some((v) => user.roles?.includes(v));
|
|
||||||
}
|
|
||||||
|
|
||||||
type EmployeeInCountryNoticePayload = {
|
|
||||||
noticeNumber: string;
|
|
||||||
noticeDate: string;
|
|
||||||
nextNoticeDate: Date;
|
|
||||||
tmNumber: string;
|
|
||||||
entryDate: Date;
|
|
||||||
travelBy: string;
|
|
||||||
travelFrom: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
@Route("api/v1/employee/{employeeId}/in-country-notice")
|
|
||||||
@Tags("Employee In Country Notice")
|
|
||||||
@Middlewares(permissionCheck(globalAllow))
|
|
||||||
export class EmployeeInCountryNoticeController extends Controller {
|
|
||||||
@Get()
|
|
||||||
@Security("keycloak")
|
|
||||||
async list(@Path() employeeId: string) {
|
|
||||||
return prisma.employeeInCountryNotice.findMany({
|
|
||||||
orderBy: { noticeDate: "desc" },
|
|
||||||
where: { employeeId },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get("{noticeId}")
|
|
||||||
@Security("keycloak")
|
|
||||||
async getById(@Path() employeeId: string, @Path() noticeId: string) {
|
|
||||||
const record = await prisma.employeeInCountryNotice.findFirst({
|
|
||||||
where: { id: noticeId, employeeId },
|
|
||||||
});
|
|
||||||
if (!record) throw notFoundError("Notice");
|
|
||||||
return record;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post()
|
|
||||||
@Security("keycloak", MANAGE_ROLES)
|
|
||||||
async create(@Path() employeeId: string, @Body() body: EmployeeInCountryNoticePayload) {
|
|
||||||
const record = await prisma.employeeInCountryNotice.create({
|
|
||||||
data: {
|
|
||||||
...body,
|
|
||||||
employee: { connect: { id: employeeId } },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setStatus(HttpStatus.CREATED);
|
|
||||||
|
|
||||||
return record;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Put("{noticeId}")
|
|
||||||
@Security("keycloak", MANAGE_ROLES)
|
|
||||||
async editById(
|
|
||||||
@Path() employeeId: string,
|
|
||||||
@Path() noticeId: string,
|
|
||||||
@Body() body: EmployeeInCountryNoticePayload,
|
|
||||||
) {
|
|
||||||
const work = await prisma.employeeInCountryNotice.findUnique({
|
|
||||||
where: { id: noticeId, employeeId },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!work) throw notFoundError("Notice");
|
|
||||||
|
|
||||||
const record = await prisma.employeeInCountryNotice.update({
|
|
||||||
where: { id: noticeId, employeeId },
|
|
||||||
data: { ...body },
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setStatus(HttpStatus.CREATED);
|
|
||||||
|
|
||||||
return record;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete("{noticeId}")
|
|
||||||
@Security("keycloak", MANAGE_ROLES)
|
|
||||||
async deleteById(@Path() employeeId: string, @Path() noticeId: string) {
|
|
||||||
const record = await prisma.employeeInCountryNotice.findFirst({
|
|
||||||
where: { id: noticeId, employeeId },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!record) throw notFoundError("Notice");
|
|
||||||
|
|
||||||
await deleteFile(fileLocation.employee.inCountryNotice(employeeId, noticeId));
|
|
||||||
|
|
||||||
return await prisma.employeeInCountryNotice.delete({ where: { id: noticeId, employeeId } });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue