Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: queryFallback utility #114

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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