2018-07-05 10:22:43 +02:00

79 lines
1.3 KiB
Plaintext
Executable File

'use strict';
/**
* <%= filename %> controller
*
* @description: A set of functions called "actions" for managing `<%= globalID %>`.
*/
module.exports = {
/**
* Retrieve <%= id %> records.
*
* @return {Object|Array}
*/
find: async (ctx) => {
if (ctx.query._q) {
return strapi.services.<%= id %>.search(ctx.query);
} else {
return strapi.services.<%= id %>.fetchAll(ctx.query);
}
},
/**
* Retrieve a <%= id %> record.
*
* @return {Object}
*/
findOne: async (ctx) => {
if (!ctx.params._id.match(/^[0-9a-fA-F]{24}$/)) {
return ctx.notFound();
}
return strapi.services.<%= id %>.fetch(ctx.params);
},
/**
* Count <%= id %> records.
*
* @return {Number}
*/
count: async (ctx) => {
return strapi.services.<%= id %>.count(ctx.query);
},
/**
* Create a/an <%= id %> record.
*
* @return {Object}
*/
create: async (ctx) => {
return strapi.services.<%= id %>.add(ctx.request.body);
},
/**
* Update a/an <%= id %> record.
*
* @return {Object}
*/
update: async (ctx, next) => {
return strapi.services.<%= id %>.edit(ctx.params, ctx.request.body) ;
},
/**
* Destroy a/an <%= id %> record.
*
* @return {Object}
*/
destroy: async (ctx, next) => {
return strapi.services.<%= id %>.remove(ctx.params);
}
};