115 lines
2.2 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
/**
2017-01-11 18:24:26 +01:00
* Retrieve <%= subId || id %> records.
2016-03-18 11:12:50 +01:00
*
* @return {Object|Array}
*/
2017-01-11 18:24:26 +01:00
find: async (ctx) => {
const data = await strapi.services.<%= subId || id %>.fetchAll(ctx.query);
// Send 200 `ok`
ctx.send(data);
2016-03-18 11:12:50 +01:00
},
/**
2017-01-11 18:24:26 +01:00
* Retrieve a <%= subId || 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) => {
const data = await strapi.services.<%= subId || id %>.fetch(ctx.params);
// Send 200 `ok`
ctx.send(data);
2016-03-18 11:12:50 +01:00
},
/**
2017-01-11 18:24:26 +01:00
* Create a/an <%= subId || id %> record.
2016-03-18 11:12:50 +01:00
*
* @return {Object}
*/
2017-01-11 18:24:26 +01:00
create: async (ctx) => {
const data = await strapi.services.<%= subId || id %>.add(ctx.request.body);
// Send 201 `created`
ctx.created(data);
2016-03-18 11:12:50 +01:00
},
/**
2017-01-11 18:24:26 +01:00
* Update a/an <%= subId || id %> record.
2016-03-18 11:12:50 +01:00
*
* @return {Object}
*/
2016-11-28 11:34:05 +01:00
update: async (ctx, next) => {
2017-01-11 18:24:26 +01:00
const data = await strapi.services.<%= subId || id %>.edit(ctx.params, ctx.request.body) ;
// Send 200 `ok`
ctx.send(data);
2016-03-18 11:12:50 +01:00
},
/**
2017-01-11 18:24:26 +01:00
* Destroy a/an <%= subId || id %> record.
2016-03-18 11:12:50 +01:00
*
* @return {Object}
*/
2016-11-28 11:34:05 +01:00
destroy: async (ctx, next) => {
2017-01-11 18:24:26 +01:00
const data = await strapi.services.<%= subId || id %>.remove(ctx.params);
// Send 200 `ok`
ctx.send(data);
},
/**
2017-01-11 18:24:26 +01:00
* Add relation to a/an <%= subId || id %> record.
*
* @return {Object}
*/
createRelation: async (ctx, next) => {
2017-01-11 18:24:26 +01:00
const data = await strapi.services.<%= subId || id %>.addRelation(ctx.params, ctx.request.body);
// Send 200 `ok`
ctx.send(data);
},
/**
2017-01-11 18:24:26 +01:00
* Update relation to a/an <%= subId || id %> record.
*
* @return {Object}
*/
updateRelation: async (ctx, next) => {
2017-01-11 18:24:26 +01:00
const data = await strapi.services.<%= subId || id %>.editRelation(ctx.params, ctx.request.body);
// Send 200 `ok`
ctx.send(data);
},
/**
2017-01-11 18:24:26 +01:00
* Destroy relation to a/an <%= subId || id %> record.
*
* @return {Object}
*/
destroyRelation: async (ctx, next) => {
2017-01-11 18:24:26 +01:00
const data = await strapi.services.<%= subId || id %>.removeRelation(ctx.params, ctx.request.body);
// Send 200 `ok`
ctx.send(data);
2016-03-18 11:12:50 +01:00
}
};