From 6e0438e568ff4b2384138418ab7f9b243ad1ed9a Mon Sep 17 00:00:00 2001 From: casperiv0 <53900565+casperiv0@users.noreply.github.com> Date: Fri, 13 Oct 2023 15:43:16 +0200 Subject: [PATCH] chore: minor improvements --- ...Settings.ts => cad-settings-controller.ts} | 30 ++++++++++--------- ...r.ts => cad-settings-images-controller.ts} | 0 2 files changed, 16 insertions(+), 14 deletions(-) rename apps/api/src/controllers/admin/manage/cad-settings/{CadSettings.ts => cad-settings-controller.ts} (97%) rename apps/api/src/controllers/admin/manage/cad-settings/{CADImagesController.ts => cad-settings-images-controller.ts} (100%) diff --git a/apps/api/src/controllers/admin/manage/cad-settings/CadSettings.ts b/apps/api/src/controllers/admin/manage/cad-settings/cad-settings-controller.ts similarity index 97% rename from apps/api/src/controllers/admin/manage/cad-settings/CadSettings.ts rename to apps/api/src/controllers/admin/manage/cad-settings/cad-settings-controller.ts index 20cdbb3de..6b006645d 100644 --- a/apps/api/src/controllers/admin/manage/cad-settings/CadSettings.ts +++ b/apps/api/src/controllers/admin/manage/cad-settings/cad-settings-controller.ts @@ -186,20 +186,22 @@ export class CADSettingsController { ): Promise { const data = validateSchema(DISABLED_FEATURES_SCHEMA, body); - for (const feature of data.features) { - const createUpdateData = { - isEnabled: feature.isEnabled, - feature: feature.feature as Feature, - extraFields: JSON.stringify(feature.extraFields), - cadId: cad.id, - }; - - await prisma.cadFeature.upsert({ - where: { feature: feature.feature as Feature }, - create: createUpdateData, - update: createUpdateData, - }); - } + await prisma.$transaction( + data.features.map((feature) => { + const createUpdateData = { + isEnabled: feature.isEnabled, + feature: feature.feature as Feature, + extraFields: JSON.stringify(feature.extraFields), + cadId: cad.id, + }; + + return prisma.cadFeature.upsert({ + where: { feature: feature.feature as Feature }, + create: createUpdateData, + update: createUpdateData, + }); + }), + ); const updated = await prisma.cad.findUniqueOrThrow({ where: { id: cad.id }, diff --git a/apps/api/src/controllers/admin/manage/cad-settings/CADImagesController.ts b/apps/api/src/controllers/admin/manage/cad-settings/cad-settings-images-controller.ts similarity index 100% rename from apps/api/src/controllers/admin/manage/cad-settings/CADImagesController.ts rename to apps/api/src/controllers/admin/manage/cad-settings/cad-settings-images-controller.ts