From e2147ea5b6a49604014aed8d8dd84c9b2e98d93b Mon Sep 17 00:00:00 2001 From: Boaz Poolman Date: Mon, 23 Oct 2023 21:06:04 +0200 Subject: [PATCH] fix: queryFallback utility --- server/config/type.js | 10 +++++++--- server/utils/queryFallBack.js | 13 ++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/server/config/type.js b/server/config/type.js index 4ae6d54..3bb3b46 100644 --- a/server/config/type.js +++ b/server/config/type.js @@ -70,11 +70,15 @@ const ConfigType = class ConfigType { }); await Promise.all(relations.map(async (relation) => { - await queryFallBack.delete(queryString, relation.id); + await queryFallBack.delete(queryString, { where: { + id: relation.id, + }}); })); })); - await queryFallBack.delete(this.queryString, existingConfig.id); + await queryFallBack.delete(this.queryString, { where: { + id: existingConfig.id, + }}); return; } @@ -111,7 +115,7 @@ const ConfigType = class ConfigType { // Update entity. this.relations.map(({ relationName }) => delete query[relationName]); - const entity = queryFallBack.update(this.queryString, { where: combinedUidWhereFilter, data: query }); + const entity = await queryFallBack.update(this.queryString, { where: combinedUidWhereFilter, data: query }); // Delete/create relations. await Promise.all(this.relations.map(async ({ queryString, relationName, parentName, relationSortFields }) => { diff --git a/server/utils/queryFallBack.js b/server/utils/queryFallBack.js index dda81e7..1a4a06f 100644 --- a/server/utils/queryFallBack.js +++ b/server/utils/queryFallBack.js @@ -10,21 +10,20 @@ const queryFallBack = { }, update: async (queryString, options) => { try { - const entity = await strapi.query(queryString).findOne(options.where); - const updatedEntity = await strapi.entityService.update(queryString, entity.id); + const entity = await strapi.query(queryString).findOne(options); + const updatedEntity = await strapi.entityService.update(queryString, entity.id, options); return updatedEntity; } catch (e) { return strapi.query(queryString).update(options); } }, - delete: async (queryString, id) => { + delete: async (queryString, options) => { try { - await strapi.entityService.delete(queryString, id); + const entity = await strapi.query(queryString).findOne(options); + await strapi.entityService.delete(queryString, entity.id); } catch (e) { - await strapi.query(queryString).delete({ - where: { id }, - }); + await strapi.query(queryString).delete(options); } }, };