refactor: quotation query and relation

This commit is contained in:
Methapon Metanipat 2024-09-30 14:31:27 +07:00
parent 9358cac3f8
commit 4f4b8df9a3

View file

@ -185,17 +185,22 @@ export class QuotationController extends Controller {
@Request() req: RequestWithUser,
@Query() page: number = 1,
@Query() pageSize: number = 30,
@Query() payCondition?: PayCondition,
) {
const where = {
payCondition,
customerBranch: {
customer: {
registeredBranch: isSystem(req.user) ? undefined : { OR: permissionCond(req.user) },
},
},
} satisfies Prisma.QuotationWhereInput;
const [result, total] = await prisma.$transaction([
prisma.quotation.findMany({
where: {
customerBranch: {
customer: {
registeredBranch: isSystem(req.user) ? undefined : { OR: permissionCond(req.user) },
},
},
},
where,
include: {
customerBranch: true,
worker: true,
service: {
include: {
@ -209,7 +214,7 @@ export class QuotationController extends Controller {
},
},
}),
prisma.quotation.count(),
prisma.quotation.count({ where }),
]);
return { result: result, page, pageSize, total };