fix: sql query

This commit is contained in:
Methapon2001 2024-07-05 11:02:18 +07:00
parent cdceac8568
commit a4c220c700

View file

@ -64,11 +64,11 @@ export class ProductServiceController extends Controller {
if (query) or.push(Prisma.sql`"name" LIKE ${`%${query}%`}`); if (query) or.push(Prisma.sql`"name" LIKE ${`%${query}%`}`);
if (status) and.push(Prisma.sql`"status" = ${status}::"Status"`); if (status) and.push(Prisma.sql`"status" = ${status}::"Status"`);
if (productTypeId) { if (productTypeId) {
and.push(Prisma.sql`("productTypeId" = ${productTypeId})`); and.push(Prisma.sql`"productTypeId" = ${productTypeId}`);
} }
if (registeredBranchId) { if (registeredBranchId) {
and.push( and.push(
Prisma.sql`("registeredBranchId" = ${registeredBranchId} OR "registeredBranchId" = null)`, Prisma.sql`("registeredBranchId" = ${registeredBranchId} OR "registeredBranchId" IS NULL)`,
); );
} }
@ -78,6 +78,7 @@ export class ProductServiceController extends Controller {
${or.length > 0 && and.length > 0 ? Prisma.sql` AND ` : Prisma.empty} ${or.length > 0 && and.length > 0 ? Prisma.sql` AND ` : Prisma.empty}
${and.length > 0 ? Prisma.join(and, " AND ", "(", ")") : Prisma.empty} ${and.length > 0 ? Prisma.join(and, " AND ", "(", ")") : Prisma.empty}
`; `;
console.log(where.sql);
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" }))[]>`