Skip to content

Commit

Permalink
Merge pull request #114 from boazpoolman/feature/update-query-fallback
Browse files Browse the repository at this point in the history
fix: queryFallback utility
  • Loading branch information
boazpoolman authored Oct 23, 2023
2 parents dd6e2f6 + e2147ea commit 7e78f04
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
10 changes: 7 additions & 3 deletions server/config/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 }) => {
Expand Down
13 changes: 6 additions & 7 deletions server/utils/queryFallBack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
};
Expand Down

0 comments on commit 7e78f04

Please sign in to comment.