mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 08:19:07 +00:00
Fix naming
This commit is contained in:
parent
34153ec9cb
commit
b6903cd77b
@ -26,39 +26,36 @@ const createEntityQuery = (strapi: Strapi.Strapi) => {
|
||||
|
||||
return assign(entityComponents, dataWithoutComponents);
|
||||
},
|
||||
create: async <T>(uid: string, data: T) => {
|
||||
return data;
|
||||
},
|
||||
get: async <T extends object>(uid: string, entity: T) => {
|
||||
return componentsService.getComponents(uid, entity);
|
||||
},
|
||||
delete<T extends object>(uid: string, components: T) {
|
||||
return componentsService.deleteComponents(uid, components, { loadComponents: false });
|
||||
delete<T extends object>(uid: string, componentsToDelete: T) {
|
||||
return componentsService.deleteComponents(uid, componentsToDelete, { loadComponents: false });
|
||||
},
|
||||
};
|
||||
|
||||
const query = (uid: string) => {
|
||||
const create = async <T extends { data: U }, U extends object>(query: T) => {
|
||||
const dataWithComponents = await components.assignToEntity(uid, query.data);
|
||||
const create = async <T extends { data: U }, U extends object>(params: T) => {
|
||||
const dataWithComponents = await components.assignToEntity(uid, params.data);
|
||||
const sanitizedData = omitInvalidCreationAttributes(dataWithComponents);
|
||||
|
||||
return strapi.db.query(uid).create({ ...query, data: sanitizedData });
|
||||
return strapi.db.query(uid).create({ ...params, data: sanitizedData });
|
||||
};
|
||||
|
||||
const createMany = async <T extends { data: U[] }, U extends object>(query: T) => {
|
||||
const createMany = async <T extends { data: U[] }, U extends object>(params: T) => {
|
||||
return (
|
||||
Promise.resolve(query.data)
|
||||
Promise.resolve(params.data)
|
||||
// Create components for each entity
|
||||
.then(map((data) => components.assignToEntity(uid, data)))
|
||||
// Remove unwanted attributes
|
||||
.then(map(omitInvalidCreationAttributes))
|
||||
// Execute a strapi db createMany query with all the entities + their created components
|
||||
.then((data) => strapi.db.query(uid).createMany({ ...query, data }))
|
||||
.then((data) => strapi.db.query(uid).createMany({ ...params, data }))
|
||||
);
|
||||
};
|
||||
|
||||
const deleteMany = async <T extends object>(query?: T) => {
|
||||
const entitiesToDelete = await strapi.db.query(uid).findMany(query ?? {});
|
||||
const deleteMany = async <T extends object>(params?: T) => {
|
||||
const entitiesToDelete = await strapi.db.query(uid).findMany(params ?? {});
|
||||
|
||||
if (!entitiesToDelete.length) {
|
||||
return null;
|
||||
@ -68,7 +65,7 @@ const createEntityQuery = (strapi: Strapi.Strapi) => {
|
||||
entitiesToDelete.map((entityToDelete) => components.get(uid, entityToDelete))
|
||||
);
|
||||
|
||||
const deletedEntities = await strapi.db.query(uid).deleteMany(query);
|
||||
const deletedEntities = await strapi.db.query(uid).deleteMany(params);
|
||||
await Promise.all(componentsToDelete.map((compos) => components.delete(uid, compos)));
|
||||
|
||||
return deletedEntities;
|
||||
|
Loading…
x
Reference in New Issue
Block a user