feat: add get quotation by id endpoint

This commit is contained in:
Methapon2001 2024-07-19 10:41:37 +07:00
parent d0e207de7e
commit fe50a31e08

View file

@ -14,6 +14,9 @@ import {
Tags, Tags,
} from "tsoa"; } from "tsoa";
import { RequestWithUser } from "../interfaces/user"; import { RequestWithUser } from "../interfaces/user";
import prisma from "../db";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
type QuotationCreate = { type QuotationCreate = {
status?: Status; status?: Status;
@ -26,14 +29,42 @@ type QuotationCreate = {
payBillDate?: number; payBillDate?: number;
workerCount: number; workerCount: number;
workerId: string[]; // EmployeeId // EmployeeId or Create new employee
worker: (
| string
| {
dateOfBirth: Date;
gender: string;
nationality: string;
firstName: string;
firstNameEN: string;
lastName: string;
lastNameEN: string;
addressEN: string;
address: string;
zipCode: string;
passportType: string;
passportNumber: string;
passportIssueDate: Date;
passportExpiryDate: Date;
passportIssuingCountry: string;
passportIssuingPlace: string;
previousPassportReference?: string;
}
)[];
customerBranchId: string;
customerId: string;
urgent?: boolean; urgent?: boolean;
service: { service: {
id: string; id: string;
// Other fields will come from original data // Other fields will come from original data
work?: { work: {
// Name field will come from original data // Name field will come from original data
product: { product: {
id: string; id: string;
@ -42,7 +73,7 @@ type QuotationCreate = {
pricePerUnit: number; pricePerUnit: number;
}[]; }[];
}[]; }[];
}; }[];
}; };
type QuotationUpdate = { type QuotationUpdate = {
@ -56,14 +87,42 @@ type QuotationUpdate = {
payBillDate?: number; payBillDate?: number;
workerCount: number; workerCount: number;
workerId: string[]; // EmployeeId // EmployeeId or Create new employee
worker?: (
| string
| {
dateOfBirth: Date;
gender: string;
nationality: string;
firstName: string;
firstNameEN: string;
lastName: string;
lastNameEN: string;
addressEN: string;
address: string;
zipCode: string;
passportType: string;
passportNumber: string;
passportIssueDate: Date;
passportExpiryDate: Date;
passportIssuingCountry: string;
passportIssuingPlace: string;
previousPassportReference?: string;
}
)[];
customerBranchId: string;
customerId: string;
urgent?: boolean; urgent?: boolean;
service: { service: {
id: string; id: string;
// Other fields will come from original data // Other fields will come from original data
work?: { work: {
// Name field will come from original data // Name field will come from original data
product: { product: {
id: string; id: string;
@ -72,7 +131,7 @@ type QuotationUpdate = {
pricePerUnit: number; pricePerUnit: number;
}[]; }[];
}[]; }[];
}; }[];
}; };
@Route("/api/v1/quotation") @Route("/api/v1/quotation")
@ -80,11 +139,33 @@ type QuotationUpdate = {
export class QuotationController extends Controller { export class QuotationController extends Controller {
@Get("{quotationId}") @Get("{quotationId}")
@Security("keycloak") @Security("keycloak")
async getQuotationById( async getQuotationById(@Path() quotationId: string) {
@Path() quotationId: string, const record = await prisma.quotation.findUnique({
@Query() page: number = 1, include: {
@Query() pageSize: number = 30, worker: true,
) {} service: {
include: {
_count: { select: { work: true } },
work: {
include: {
_count: { select: { productOnWork: true } },
productOnWork: {
include: { product: true },
},
},
},
},
},
},
where: { id: quotationId },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "Quotation not found.", "quotationNotFound");
}
return record;
}
@Get() @Get()
@Security("keycloak") @Security("keycloak")