123 lines
2.2 KiB
Plaintext
Raw Normal View History

2016-03-18 11:12:50 +01:00
'use strict';
/**
* A set of functions called "actions" for `<%= globalID %>`
*/
module.exports = {
/**
* Get <%= id %> entries.
*
* @return {Object|Array}
*/
find: async (ctx, next) => {
2016-03-18 11:12:50 +01:00
try {
ctx.body = await strapi.services.<%= id %>.fetchAll(ctx.query);
2016-03-18 11:12:50 +01:00
} catch (err) {
ctx.body = err;
2016-03-18 11:12:50 +01:00
}
},
/**
* Get a specific <%= id %>.
*
* @return {Object|Array}
*/
findOne: async (ctx, next) => {
2016-03-18 11:12:50 +01:00
try {
ctx.body = await strapi.services.<%= id %>.fetch(ctx.params)
2016-03-18 11:12:50 +01:00
} catch (err) {
ctx.body = err;
2016-03-18 11:12:50 +01:00
}
},
/**
* Create a/an <%= id %> entry.
*
* @return {Object}
*/
create: async (ctx, next) => {
2016-03-18 11:12:50 +01:00
try {
ctx.body = await strapi.services.<%= id %>.add(ctx.request.body);
2016-03-18 11:12:50 +01:00
} catch (err) {
ctx.body = err;
2016-03-18 11:12:50 +01:00
}
},
/**
* Update a/an <%= id %> entry.
*
* @return {Object}
*/
update: async (ctx, next) => {
2016-03-18 11:12:50 +01:00
try {
ctx.body = await strapi.services.<%= id %>.edit(ctx.params, ctx.request.body) ;
2016-03-18 11:12:50 +01:00
} catch (err) {
ctx.body = err;
2016-03-18 11:12:50 +01:00
}
},
/**
* Destroy a/an <%= id %> entry.
*
* @return {Object}
*/
destroy: async (ctx, next) => {
2016-03-18 11:12:50 +01:00
try {
ctx.body = await strapi.services.<%= id %>.remove(ctx.params);
2016-03-18 11:12:50 +01:00
} catch (err) {
ctx.body = err;
2016-03-18 11:12:50 +01:00
}
},
/**
* Add relation to a specific <%= id %>.
*
* @return {Object}
*/
createRelation: async (ctx, next) => {
2016-03-18 11:12:50 +01:00
try {
ctx.body = await strapi.services.<%= id %>.addRelation(ctx.params, ctx.request.body);
2016-03-18 11:12:50 +01:00
} catch (err) {
ctx.status = 400;
ctx.body = err;
2016-03-18 11:12:50 +01:00
}
},
/**
* Update relation to a specific <%= id %>.
*
* @return {Object}
*/
updateRelation: async (ctx, next) => {
try {
ctx.body = await strapi.services.<%= id %>.editRelation(ctx.params, ctx.request.body);
} catch (err) {
ctx.status = 400;
ctx.body = err;
}
},
2016-03-18 11:12:50 +01:00
/**
* Destroy relation to a specific <%= id %>.
*
* @return {Object}
*/
destroyRelation: async (ctx, next) => {
2016-03-18 11:12:50 +01:00
try {
ctx.body = await strapi.services.<%= id %>.removeRelation(ctx.params, ctx.request.body);
2016-03-18 11:12:50 +01:00
} catch (err) {
ctx.status = 400;
ctx.body = err;
2016-03-18 11:12:50 +01:00
}
}
};