mirror of
https://github.com/strapi/strapi.git
synced 2025-08-31 12:23:05 +00:00
123 lines
2.3 KiB
Plaintext
Executable File
123 lines
2.3 KiB
Plaintext
Executable File
'use strict';
|
|
|
|
/**
|
|
* A set of functions called "actions" for `<%= globalID %>`
|
|
*/
|
|
|
|
module.exports = {
|
|
/**
|
|
* Get <%= subId || id %> entries.
|
|
*
|
|
* @return {Object|Array}
|
|
*/
|
|
|
|
find: async (ctx, next) => {
|
|
try {
|
|
ctx.body = await strapi.services.<%= subId || id %>.fetchAll(ctx.query);
|
|
} catch (err) {
|
|
ctx.body = err;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Get a specific <%= subId || id %>.
|
|
*
|
|
* @return {Object|Array}
|
|
*/
|
|
|
|
findOne: async (ctx, next) => {
|
|
try {
|
|
ctx.body = await strapi.services.<%= subId || id %>.fetch(ctx.params)
|
|
} catch (err) {
|
|
ctx.body = err;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Create a/an <%= subId || id %> entry.
|
|
*
|
|
* @return {Object}
|
|
*/
|
|
|
|
create: async (ctx, next) => {
|
|
try {
|
|
ctx.body = await strapi.services.<%= subId || id %>.add(ctx.request.body);
|
|
} catch (err) {
|
|
ctx.body = err;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Update a/an <%= subId || id %> entry.
|
|
*
|
|
* @return {Object}
|
|
*/
|
|
|
|
update: async (ctx, next) => {
|
|
try {
|
|
ctx.body = await strapi.services.<%= subId || id %>.edit(ctx.params, ctx.request.body) ;
|
|
} catch (err) {
|
|
ctx.body = err;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Destroy a/an <%= subId || id %> entry.
|
|
*
|
|
* @return {Object}
|
|
*/
|
|
|
|
destroy: async (ctx, next) => {
|
|
try {
|
|
ctx.body = await strapi.services.<%= subId || id %>.remove(ctx.params);
|
|
} catch (err) {
|
|
ctx.body = err;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Add relation to a specific <%= subId || id %>.
|
|
*
|
|
* @return {Object}
|
|
*/
|
|
|
|
createRelation: async (ctx, next) => {
|
|
try {
|
|
ctx.body = await strapi.services.<%= subId || id %>.addRelation(ctx.params, ctx.request.body);
|
|
} catch (err) {
|
|
ctx.status = 400;
|
|
ctx.body = err;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Update relation to a specific <%= subId || id %>.
|
|
*
|
|
* @return {Object}
|
|
*/
|
|
|
|
updateRelation: async (ctx, next) => {
|
|
try {
|
|
ctx.body = await strapi.services.<%= subId || id %>.editRelation(ctx.params, ctx.request.body);
|
|
} catch (err) {
|
|
ctx.status = 400;
|
|
ctx.body = err;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Destroy relation to a specific <%= subId || id %>.
|
|
*
|
|
* @return {Object}
|
|
*/
|
|
|
|
destroyRelation: async (ctx, next) => {
|
|
try {
|
|
ctx.body = await strapi.services.<%= subId || id %>.removeRelation(ctx.params, ctx.request.body);
|
|
} catch (err) {
|
|
ctx.status = 400;
|
|
ctx.body = err;
|
|
}
|
|
}
|
|
};
|