68 lines
1.1 KiB
JavaScript
Raw Normal View History

'use strict';
/**
* A set of functions called "actions" for `ContentManager`
*/
module.exports = {
models: async(ctx) => {
ctx.body = strapi.models;
},
find: async(ctx) => {
const model = ctx.params.model;
2017-04-11 11:34:59 +02:00
const {
limit = 10,
skip = 0,
2017-04-21 17:19:41 +02:00
sort = '_id'
2017-04-11 11:34:59 +02:00
} = ctx.request.query;
const entries = await User
2017-04-11 11:34:59 +02:00
.find()
.limit(Number(limit))
2017-04-11 13:44:47 +02:00
.sort(sort)
.skip(Number(skip));
ctx.body = entries;
},
2017-04-11 11:34:59 +02:00
count: async(ctx) => {
const model = ctx.params.model;
const count = await User
.count();
ctx.body = {
count: Number(count)
};
},
findOne: async(ctx) => {
const model = ctx.params.model;
const _id = ctx.params.id;
const entries = await User
.findOne({
_id
});
ctx.body = entries;
2017-04-21 17:19:41 +02:00
},
update: async(ctx) => {
const entryUpdated = await User
2017-04-21 17:52:18 +02:00
.update({_id: ctx.request.params.id}, ctx.request.body);
2017-04-21 17:19:41 +02:00
2017-04-21 17:52:18 +02:00
ctx.body = entryUpdated;
},
delete: async(ctx) => {
const entryDeleted = await User
.remove({_id: ctx.request.params.id});
ctx.body = entryDeleted;
}
};