Move ML find many to find page

This commit is contained in:
Alexandre Bodin 2021-10-07 17:23:42 +02:00
parent fdc0fa82fc
commit 7676bf8890
4 changed files with 27 additions and 4 deletions

View File

@ -37,7 +37,7 @@ module.exports = {
const query = pm.addPermissionsQueryTo(ctx.query);
const files = await getService('upload').fetchAll(query);
const files = await getService('upload').findPage(query);
ctx.body = pm.sanitize(files, { withPrivate: false });
},

View File

@ -15,7 +15,7 @@ const sanitize = (data, options = {}) => {
module.exports = {
async find(ctx) {
const files = await getService('upload').fetchAll(ctx.query);
const files = await getService('upload').findMany(ctx.query);
ctx.body = sanitize(files);
},

View File

@ -302,10 +302,14 @@ module.exports = ({ strapi }) => ({
return strapi.entityService.findOne('plugin::upload.file', id, { populate });
},
fetchAll(query) {
findMany(query) {
return strapi.entityService.findMany('plugin::upload.file', query);
},
findPage(query) {
return strapi.entityService.findPage('plugin::upload.file', query);
},
count(query) {
return strapi.entityService.count('plugin::upload.file', query);
},

View File

@ -142,7 +142,26 @@ describe('Upload plugin end to end tests', () => {
});
});
test.todo('GET /upload/files => Find files');
test('GET /upload/files => Find files', async () => {
const getRes = await rq({ method: 'GET', url: '/upload/files' });
expect(getRes.statusCode).toBe(200);
expect(getRes.body).toEqual({
results: expect.arrayContaining([
expect.objectContaining({
id: expect.anything(),
url: expect.any(String),
}),
]),
pagination: {
page: expect.any(Number),
pageSize: expect.any(Number),
pageCount: expect.any(Number),
total: expect.any(Number),
},
});
});
test.todo('GET /upload/files/count => Count available files');
test.todo('GET /upload/files/:id => Find one file');
test.todo('GET /upload/search/:id => Search files');