79 lines
1.3 KiB
Plaintext
Raw Normal View History

2016-03-18 11:12:50 +01:00
'use strict';
/**
2017-01-11 18:24:26 +01:00
* <%= filename %> controller
*
* @description: A set of functions called "actions" for managing `<%= globalID %>`.
2016-03-18 11:12:50 +01:00
*/
module.exports = {
2017-01-11 18:24:26 +01:00
2016-03-18 11:12:50 +01:00
/**
* Retrieve <%= id %> records.
2016-03-18 11:12:50 +01:00
*
* @return {Object|Array}
*/
2017-01-11 18:24:26 +01:00
find: async (ctx) => {
2018-07-05 10:22:43 +02:00
if (ctx.query._q) {
return strapi.services.<%= id %>.search(ctx.query);
} else {
return strapi.services.<%= id %>.fetchAll(ctx.query);
}
2016-03-18 11:12:50 +01:00
},
/**
* Retrieve a <%= id %> record.
2016-03-18 11:12:50 +01:00
*
2017-01-11 18:24:26 +01:00
* @return {Object}
2016-03-18 11:12:50 +01:00
*/
2017-01-11 18:24:26 +01:00
findOne: async (ctx) => {
if (!ctx.params._id.match(/^[0-9a-fA-F]{24}$/)) {
return ctx.notFound();
}
return strapi.services.<%= id %>.fetch(ctx.params);
2016-03-18 11:12:50 +01:00
},
2018-05-29 15:48:07 +03:00
/**
* Count <%= id %> records.
*
* @return {Number}
*/
count: async (ctx) => {
return strapi.services.<%= id %>.count(ctx.query);
},
2016-03-18 11:12:50 +01:00
/**
* Create a/an <%= id %> record.
2016-03-18 11:12:50 +01:00
*
* @return {Object}
*/
2017-01-11 18:24:26 +01:00
create: async (ctx) => {
return strapi.services.<%= id %>.add(ctx.request.body);
2016-03-18 11:12:50 +01:00
},
/**
* Update a/an <%= id %> record.
2016-03-18 11:12:50 +01:00
*
* @return {Object}
*/
2016-11-28 11:34:05 +01:00
update: async (ctx, next) => {
return strapi.services.<%= id %>.edit(ctx.params, ctx.request.body) ;
2016-03-18 11:12:50 +01:00
},
/**
* Destroy a/an <%= id %> record.
2016-03-18 11:12:50 +01:00
*
* @return {Object}
*/
2016-11-28 11:34:05 +01:00
destroy: async (ctx, next) => {
return strapi.services.<%= id %>.remove(ctx.params);
2016-03-18 11:12:50 +01:00
}
};