2024-10-09 15:04:59 +07:00
|
|
|
import { Controller, Delete, Get, Path, Put, Query, Request, Route, Security, Tags } from "tsoa";
|
|
|
|
|
import { RequestWithUser } from "../interfaces/user";
|
|
|
|
|
import prisma from "../db";
|
2024-10-10 10:28:24 +07:00
|
|
|
import { Prisma } from "@prisma/client";
|
|
|
|
|
import { createPermCheck, createPermCondition } from "../services/permission";
|
|
|
|
|
|
|
|
|
|
// User in company can see.
|
|
|
|
|
const permissionCond = createPermCondition((_) => true);
|
2024-10-09 15:04:59 +07:00
|
|
|
|
|
|
|
|
@Route("api/v1/request-list")
|
|
|
|
|
@Tags("Request List")
|
|
|
|
|
export class RequestListController extends Controller {
|
|
|
|
|
@Get()
|
|
|
|
|
@Security("keycloak")
|
|
|
|
|
async getRequest(
|
|
|
|
|
@Request() req: RequestWithUser,
|
|
|
|
|
@Query() page: number = 1,
|
|
|
|
|
@Query() pageSize: number = 30,
|
|
|
|
|
) {
|
2024-10-10 10:28:24 +07:00
|
|
|
const where = {
|
|
|
|
|
request: {
|
|
|
|
|
quotation: {
|
|
|
|
|
customerBranch: {
|
|
|
|
|
customer: {
|
|
|
|
|
registeredBranch: { OR: permissionCond(req.user) },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
} satisfies Prisma.RequestWorkWhereInput;
|
|
|
|
|
|
2024-10-10 09:40:09 +07:00
|
|
|
const [result, total] = await prisma.$transaction([
|
|
|
|
|
prisma.requestWork.findMany({
|
2024-10-10 10:28:24 +07:00
|
|
|
where,
|
2024-10-10 09:40:09 +07:00
|
|
|
include: {
|
|
|
|
|
request: {
|
|
|
|
|
include: {
|
|
|
|
|
quotation: true,
|
|
|
|
|
employee: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
productService: {
|
|
|
|
|
include: {
|
|
|
|
|
service: true,
|
|
|
|
|
work: true,
|
|
|
|
|
product: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
take: pageSize,
|
|
|
|
|
skip: (page - 1) * pageSize,
|
|
|
|
|
}),
|
2024-10-10 10:28:24 +07:00
|
|
|
prisma.requestWork.count({ where }),
|
2024-10-10 09:40:09 +07:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return { result, page, pageSize, total };
|
2024-10-09 15:04:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get("{requestId}")
|
|
|
|
|
async getRequestById(@Path() requestId: string) {
|
|
|
|
|
return await prisma.requestWork.findFirst({
|
2024-10-10 09:40:09 +07:00
|
|
|
include: {
|
|
|
|
|
request: {
|
|
|
|
|
include: {
|
|
|
|
|
quotation: true,
|
|
|
|
|
employee: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
productService: {
|
|
|
|
|
include: {
|
|
|
|
|
service: true,
|
|
|
|
|
work: true,
|
|
|
|
|
product: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-10-09 15:04:59 +07:00
|
|
|
where: { id: requestId },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @todo */
|
|
|
|
|
@Put("{requestId}")
|
|
|
|
|
async updateRequestById(@Request() req: RequestWithUser, @Path() requestId: string) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @todo */
|
|
|
|
|
@Delete("{requestId}")
|
|
|
|
|
async deleteRequestById(@Request() req: RequestWithUser, @Path() requestId: string) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class RequestListAttachmentController extends Controller {}
|