diff --git a/pkgs/utils/query.ts b/pkgs/utils/query.ts index c08e570..1db46fb 100644 --- a/pkgs/utils/query.ts +++ b/pkgs/utils/query.ts @@ -14,30 +14,31 @@ export const execQuery = async (args: DBArg, prisma: any) => { const { table, action, params } = args; if (action === "batch_update") { - const { table, batch } = params as unknown as { + const { batch } = params as unknown as { table: string; - batch: { data: any; where: any }[]; + batch: { table: string; data: any; where: any }[]; }; const promises = [] as any[]; - const tableInstance = prisma[table]; - if (tableInstance) { - try { - for (const item of batch) { - if ( - Object.entries(item.where).length > 0 && - Object.entries(item.data).length > 0 - ) { + try { + for (const item of batch) { + if ( + item.table && + Object.entries(item.where).length > 0 && + Object.entries(item.data).length > 0 + ) { + const tableInstance = prisma[item.table]; + if (tableInstance) { promises.push( 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;