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,
} from "tsoa";
import { RequestWithUser } from "../interfaces/user";
import prisma from "../db";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
type QuotationCreate = {
status?: Status;
@ -26,14 +29,42 @@ type QuotationCreate = {
payBillDate?: 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;
service: {
id: string;
// Other fields will come from original data
work?: {
work: {
// Name field will come from original data
product: {
id: string;
@ -42,7 +73,7 @@ type QuotationCreate = {
pricePerUnit: number;
}[];
}[];
};
}[];
};
type QuotationUpdate = {
@ -56,14 +87,42 @@ type QuotationUpdate = {
payBillDate?: 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;
service: {
id: string;
// Other fields will come from original data
work?: {
work: {
// Name field will come from original data
product: {
id: string;
@ -72,7 +131,7 @@ type QuotationUpdate = {
pricePerUnit: number;
}[];
}[];
};
}[];
};
@Route("/api/v1/quotation")
@ -80,11 +139,33 @@ type QuotationUpdate = {
export class QuotationController extends Controller {
@Get("{quotationId}")
@Security("keycloak")
async getQuotationById(
@Path() quotationId: string,
@Query() page: number = 1,
@Query() pageSize: number = 30,
) {}
async getQuotationById(@Path() quotationId: string) {
const record = await prisma.quotation.findUnique({
include: {
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()
@Security("keycloak")