mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 15:13:21 +00:00
move entity to entity-manager
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
7f906d7cf2
commit
9438230648
@ -124,7 +124,7 @@ describe('Relations', () => {
|
||||
};
|
||||
},
|
||||
},
|
||||
entity: {
|
||||
'entity-manager': {
|
||||
find() {
|
||||
return [
|
||||
{
|
||||
|
||||
@ -35,7 +35,7 @@ describe('Single Types', () => {
|
||||
plugins: {
|
||||
'content-manager': {
|
||||
services: {
|
||||
entity: {
|
||||
'entity-manager': {
|
||||
find() {
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
@ -26,7 +26,7 @@ module.exports = {
|
||||
|
||||
const permissionQuery = permissionChecker.buildPermissionQuery(query);
|
||||
|
||||
const results = await getService('entity')[method](permissionQuery, model);
|
||||
const results = await getService('entity-manager')[method](permissionQuery, model);
|
||||
|
||||
ctx.body = results.map(entity => permissionChecker.sanitizeOutput(entity));
|
||||
},
|
||||
@ -41,7 +41,7 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const entity = await getService('entity').findOneWithCreatorRoles(id, model);
|
||||
const entity = await getService('entity-manager').findOneWithCreatorRoles(id, model);
|
||||
|
||||
if (!entity) {
|
||||
return ctx.notFound();
|
||||
@ -72,7 +72,10 @@ module.exports = {
|
||||
const sanitizeFn = pipe([pickWritables, pickPermittedFields, setCreator]);
|
||||
|
||||
await wrapBadRequest(async () => {
|
||||
const entity = await getService('entity').create({ data: sanitizeFn(data), files }, model);
|
||||
const entity = await getService('entity-manager').create(
|
||||
{ data: sanitizeFn(data), files },
|
||||
model
|
||||
);
|
||||
ctx.body = permissionChecker.sanitizeOutput(entity);
|
||||
|
||||
await strapi.telemetry.send('didCreateFirstContentTypeEntry', { model });
|
||||
@ -90,7 +93,7 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const entity = await getService('entity').findOneWithCreatorRoles(id, model);
|
||||
const entity = await getService('entity-manager').findOneWithCreatorRoles(id, model);
|
||||
|
||||
if (!entity) {
|
||||
return ctx.notFound();
|
||||
@ -107,7 +110,7 @@ module.exports = {
|
||||
const sanitizeFn = pipe([pickWritables, pickPermittedFields, setCreator]);
|
||||
|
||||
await wrapBadRequest(async () => {
|
||||
const updatedEntity = await getService('entity').update(
|
||||
const updatedEntity = await getService('entity-manager').update(
|
||||
entity,
|
||||
{ data: sanitizeFn(data), files },
|
||||
model
|
||||
@ -127,7 +130,7 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const entity = await getService('entity').findOneWithCreatorRoles(id, model);
|
||||
const entity = await getService('entity-manager').findOneWithCreatorRoles(id, model);
|
||||
|
||||
if (!entity) {
|
||||
return ctx.notFound();
|
||||
@ -137,7 +140,7 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const result = await getService('entity').delete(entity, model);
|
||||
const result = await getService('entity-manager').delete(entity, model);
|
||||
|
||||
ctx.body = permissionChecker.sanitizeOutput(result);
|
||||
},
|
||||
@ -152,7 +155,7 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const entity = await getService('entity').findOneWithCreatorRoles(id, model);
|
||||
const entity = await getService('entity-manager').findOneWithCreatorRoles(id, model);
|
||||
|
||||
if (!entity) {
|
||||
return ctx.notFound();
|
||||
@ -162,7 +165,7 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const result = await getService('entity').publish(entity, model);
|
||||
const result = await getService('entity-manager').publish(entity, model);
|
||||
|
||||
ctx.body = permissionChecker.sanitizeOutput(result);
|
||||
},
|
||||
@ -177,7 +180,7 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const entity = await getService('entity').findOneWithCreatorRoles(id, model);
|
||||
const entity = await getService('entity-manager').findOneWithCreatorRoles(id, model);
|
||||
|
||||
if (!entity) {
|
||||
return ctx.notFound();
|
||||
@ -187,7 +190,7 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const result = await getService('entity').unpublish(entity, model);
|
||||
const result = await getService('entity-manager').unpublish(entity, model);
|
||||
|
||||
ctx.body = permissionChecker.sanitizeOutput(result);
|
||||
},
|
||||
|
||||
@ -31,14 +31,14 @@ module.exports = {
|
||||
return ctx.notFound('target.notFound');
|
||||
}
|
||||
|
||||
const entityService = getService('entity');
|
||||
const entityManager = getService('entity-manager');
|
||||
|
||||
let entities = [];
|
||||
|
||||
if (has('_q', ctx.request.query)) {
|
||||
entities = await entityService.search(query, target.uid);
|
||||
entities = await entityManager.search(query, target.uid);
|
||||
} else {
|
||||
entities = await entityService.find(query, target.uid);
|
||||
entities = await entityManager.find(query, target.uid);
|
||||
}
|
||||
|
||||
if (!entities) {
|
||||
|
||||
@ -10,10 +10,10 @@ const {
|
||||
} = require('../utils');
|
||||
|
||||
const findEntity = async model => {
|
||||
const service = getService('entity');
|
||||
const entityManager = getService('entity-manager');
|
||||
|
||||
const entity = service.find({}, model);
|
||||
return service.assocCreatorRoles(entity);
|
||||
const entity = entityManager.find({}, model);
|
||||
return entityManager.assocCreatorRoles(entity);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
@ -73,7 +73,10 @@ module.exports = {
|
||||
|
||||
await wrapBadRequest(async () => {
|
||||
if (!entity) {
|
||||
const entity = await getService('entity').create({ data: sanitizeFn(data), files }, model);
|
||||
const entity = await getService('entity-manager').create(
|
||||
{ data: sanitizeFn(data), files },
|
||||
model
|
||||
);
|
||||
|
||||
ctx.body = permissionChecker.sanitizeOutput(entity);
|
||||
|
||||
@ -85,7 +88,7 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const updatedEntity = await getService('entity').update(
|
||||
const updatedEntity = await getService('entity-manager').update(
|
||||
entity,
|
||||
{ data: sanitizeFn(data), files },
|
||||
model
|
||||
@ -115,7 +118,7 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const deletedEntity = await getService('entity').delete(entity, model);
|
||||
const deletedEntity = await getService('entity-manager').delete(entity, model);
|
||||
|
||||
ctx.body = permissionChecker.sanitizeOutput(deletedEntity);
|
||||
},
|
||||
@ -140,7 +143,7 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const publishedEntity = await getService('entity').publish(entity, model);
|
||||
const publishedEntity = await getService('entity-manager').publish(entity, model);
|
||||
|
||||
ctx.body = permissionChecker.sanitizeOutput(publishedEntity);
|
||||
},
|
||||
@ -165,7 +168,7 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const unpublishedEntity = await getService('entity').unpublish(entity, model);
|
||||
const unpublishedEntity = await getService('entity-manager').unpublish(entity, model);
|
||||
|
||||
ctx.body = permissionChecker.sanitizeOutput(unpublishedEntity);
|
||||
},
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const contentManagerService = require('../ContentManager');
|
||||
const entityManager = require('../entity-manager');
|
||||
|
||||
describe('Content-Manager', () => {
|
||||
const fakeModel = {
|
||||
@ -13,6 +13,9 @@ describe('Content-Manager', () => {
|
||||
entityService: {
|
||||
update: jest.fn(),
|
||||
},
|
||||
entityValidator: {
|
||||
validateEntityCreation() {},
|
||||
},
|
||||
eventHub: { emit: jest.fn() },
|
||||
getModel: jest.fn(() => fakeModel),
|
||||
};
|
||||
@ -24,11 +27,11 @@ describe('Content-Manager', () => {
|
||||
|
||||
test('Publish a content-type', async () => {
|
||||
const model = 'application::test.test';
|
||||
const params = { id: 1 };
|
||||
await contentManagerService.publish(params, model);
|
||||
const entity = { id: 1, published_at: null };
|
||||
await entityManager.publish(entity, model);
|
||||
|
||||
expect(strapi.entityService.update).toBeCalledWith(
|
||||
{ params, data: { published_at: expect.any(Date) } },
|
||||
{ params: { id: entity.id }, data: { published_at: expect.any(Date) } },
|
||||
{ model }
|
||||
);
|
||||
});
|
||||
@ -51,11 +54,11 @@ describe('Content-Manager', () => {
|
||||
|
||||
test('Unpublish a content-type', async () => {
|
||||
const model = 'application::test.test';
|
||||
const params = { id: 1 };
|
||||
await contentManagerService.unpublish(params, model);
|
||||
const entity = { id: 1, published_at: new Date() };
|
||||
await entityManager.unpublish(entity, model);
|
||||
|
||||
expect(strapi.entityService.update).toHaveBeenCalledWith(
|
||||
{ params, data: { published_at: null } },
|
||||
{ params: { id: entity.id }, data: { published_at: null } },
|
||||
{ model }
|
||||
);
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user