mirror of
https://github.com/strapi/strapi.git
synced 2025-07-24 17:40:18 +00:00
115 lines
2.2 KiB
Plaintext
Executable File
115 lines
2.2 KiB
Plaintext
Executable File
'use strict';
|
|
|
|
/**
|
|
* <%= filename %> controller
|
|
*
|
|
* @description: A set of functions called "actions" for managing `<%= globalID %>`.
|
|
*/
|
|
|
|
module.exports = {
|
|
|
|
/**
|
|
* Retrieve <%= subId || id %> records.
|
|
*
|
|
* @return {Object|Array}
|
|
*/
|
|
|
|
find: async (ctx) => {
|
|
const data = await strapi.services.<%= subId || id %>.fetchAll(ctx.query);
|
|
|
|
// Send 200 `ok`
|
|
ctx.send(data);
|
|
},
|
|
|
|
/**
|
|
* Retrieve a <%= subId || id %> record.
|
|
*
|
|
* @return {Object}
|
|
*/
|
|
|
|
findOne: async (ctx) => {
|
|
const data = await strapi.services.<%= subId || id %>.fetch(ctx.params);
|
|
|
|
// Send 200 `ok`
|
|
ctx.send(data);
|
|
},
|
|
|
|
/**
|
|
* Create a/an <%= subId || id %> record.
|
|
*
|
|
* @return {Object}
|
|
*/
|
|
|
|
create: async (ctx) => {
|
|
const data = await strapi.services.<%= subId || id %>.add(ctx.request.body);
|
|
|
|
// Send 201 `created`
|
|
ctx.created(data);
|
|
},
|
|
|
|
/**
|
|
* Update a/an <%= subId || id %> record.
|
|
*
|
|
* @return {Object}
|
|
*/
|
|
|
|
update: async (ctx, next) => {
|
|
const data = await strapi.services.<%= subId || id %>.edit(ctx.params, ctx.request.body) ;
|
|
|
|
// Send 200 `ok`
|
|
ctx.send(data);
|
|
},
|
|
|
|
/**
|
|
* Destroy a/an <%= subId || id %> record.
|
|
*
|
|
* @return {Object}
|
|
*/
|
|
|
|
destroy: async (ctx, next) => {
|
|
const data = await strapi.services.<%= subId || id %>.remove(ctx.params);
|
|
|
|
// Send 200 `ok`
|
|
ctx.send(data);
|
|
},
|
|
|
|
/**
|
|
* Add relation to a/an <%= subId || id %> record.
|
|
*
|
|
* @return {Object}
|
|
*/
|
|
|
|
createRelation: async (ctx, next) => {
|
|
const data = await strapi.services.<%= subId || id %>.addRelation(ctx.params, ctx.request.body);
|
|
|
|
// Send 200 `ok`
|
|
ctx.send(data);
|
|
},
|
|
|
|
/**
|
|
* Update relation to a/an <%= subId || id %> record.
|
|
*
|
|
* @return {Object}
|
|
*/
|
|
|
|
updateRelation: async (ctx, next) => {
|
|
const data = await strapi.services.<%= subId || id %>.editRelation(ctx.params, ctx.request.body);
|
|
|
|
// Send 200 `ok`
|
|
ctx.send(data);
|
|
},
|
|
|
|
/**
|
|
* Destroy relation to a/an <%= subId || id %> record.
|
|
*
|
|
* @return {Object}
|
|
*/
|
|
|
|
destroyRelation: async (ctx, next) => {
|
|
const data = await strapi.services.<%= subId || id %>.removeRelation(ctx.params, ctx.request.body);
|
|
|
|
// Send 200 `ok`
|
|
ctx.send(data);
|
|
}
|
|
};
|