fix: total count bigint cannot be serialize

This commit is contained in:
Methapon2001 2024-06-25 09:30:08 +07:00
parent acec110c51
commit c79851d074

View file

@ -66,15 +66,15 @@ export class ProductServiceController extends Controller {
${and.length > 0 ? Prisma.join(and, " AND ", "(", ")") : Prisma.empty} ${and.length > 0 ? Prisma.join(and, " AND ", "(", ")") : Prisma.empty}
`; `;
const [result, { total }] = await prisma.$transaction([ const [result, [{ total }]] = await prisma.$transaction([
prisma.$queryRaw<((Product & { type: "product" }) | (Service & { type: "service" }))[]>` prisma.$queryRaw<((Product & { type: "product" }) | (Service & { type: "service" }))[]>`
SELECT * FROM (${union}) AS "ProductService" SELECT * FROM (${union}) AS "ProductService"
${where} ${where}
ORDER BY "ProductService"."statusOrder" ASC, "ProductService"."createdAt" ASC ORDER BY "ProductService"."statusOrder" ASC, "ProductService"."createdAt" ASC
LIMIT ${pageSize} OFFSET ${(page - 1) * pageSize} LIMIT ${pageSize} OFFSET ${(page - 1) * pageSize}
`, `,
prisma.$queryRaw<{ total: number }>` prisma.$queryRaw<[{ total: number }]>`
SELECT COUNT( * ) AS "total" FROM (${union}) as "ProductService" SELECT COUNT(*) AS "total" FROM (${union}) as "ProductService"
${where} ${where}
`, `,
]); ]);
@ -82,7 +82,7 @@ export class ProductServiceController extends Controller {
result, result,
page, page,
pageSize, pageSize,
total, total: +String(total),
}; };
} }
} }