fix: sql query
This commit is contained in:
parent
cdceac8568
commit
a4c220c700
1 changed files with 3 additions and 2 deletions
|
|
@ -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" }))[]>`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue