This commit is contained in:
Rizky 2024-03-13 15:07:27 +07:00
parent 4ac633d4a2
commit 05b58b369b
1 changed files with 14 additions and 13 deletions

View File

@ -14,30 +14,31 @@ export const execQuery = async (args: DBArg, prisma: any) => {
const { table, action, params } = args; const { table, action, params } = args;
if (action === "batch_update") { if (action === "batch_update") {
const { table, batch } = params as unknown as { const { batch } = params as unknown as {
table: string; table: string;
batch: { data: any; where: any }[]; batch: { table: string; data: any; where: any }[];
}; };
const promises = [] as any[]; const promises = [] as any[];
const tableInstance = prisma[table]; try {
if (tableInstance) { for (const item of batch) {
try { if (
for (const item of batch) { item.table &&
if ( Object.entries(item.where).length > 0 &&
Object.entries(item.where).length > 0 && Object.entries(item.data).length > 0
Object.entries(item.data).length > 0 ) {
) { const tableInstance = prisma[item.table];
if (tableInstance) {
promises.push( promises.push(
tableInstance.updateMany({ where: item.where, data: item.data }) tableInstance.updateMany({ where: item.where, data: item.data })
); );
} }
} }
await Promise.all(promises);
} catch (e: any) {
throw new Error(e.message);
} }
await Promise.all(promises);
} catch (e: any) {
throw new Error(e.message);
} }
return; return;