2016-03-18 11:12:50 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A set of functions called "actions" for `<%= globalID %>`
|
|
|
|
*/
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
/**
|
2016-12-20 20:41:42 +01:00
|
|
|
* Get <%= subId || id %> entries.
|
2016-03-18 11:12:50 +01:00
|
|
|
*
|
|
|
|
* @return {Object|Array}
|
|
|
|
*/
|
|
|
|
|
2016-11-28 11:34:05 +01:00
|
|
|
find: async (ctx, next) => {
|
2016-03-18 11:12:50 +01:00
|
|
|
try {
|
2016-12-20 20:41:42 +01:00
|
|
|
ctx.body = await strapi.services.<%= subId || id %>.fetchAll(ctx.query);
|
2016-03-18 11:12:50 +01:00
|
|
|
} catch (err) {
|
2016-11-28 11:34:05 +01:00
|
|
|
ctx.body = err;
|
2016-03-18 11:12:50 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-12-20 20:41:42 +01:00
|
|
|
* Get a specific <%= subId || id %>.
|
2016-03-18 11:12:50 +01:00
|
|
|
*
|
|
|
|
* @return {Object|Array}
|
|
|
|
*/
|
|
|
|
|
2016-11-28 11:34:05 +01:00
|
|
|
findOne: async (ctx, next) => {
|
2016-03-18 11:12:50 +01:00
|
|
|
try {
|
2016-12-20 20:41:42 +01:00
|
|
|
ctx.body = await strapi.services.<%= subId || id %>.fetch(ctx.params)
|
2016-03-18 11:12:50 +01:00
|
|
|
} catch (err) {
|
2016-11-28 11:34:05 +01:00
|
|
|
ctx.body = err;
|
2016-03-18 11:12:50 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-12-20 20:41:42 +01:00
|
|
|
* Create a/an <%= subId || id %> entry.
|
2016-03-18 11:12:50 +01:00
|
|
|
*
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
|
2016-11-28 11:34:05 +01:00
|
|
|
create: async (ctx, next) => {
|
2016-03-18 11:12:50 +01:00
|
|
|
try {
|
2016-12-20 20:41:42 +01:00
|
|
|
ctx.body = await strapi.services.<%= subId || id %>.add(ctx.request.body);
|
2016-03-18 11:12:50 +01:00
|
|
|
} catch (err) {
|
2016-11-28 11:34:05 +01:00
|
|
|
ctx.body = err;
|
2016-03-18 11:12:50 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-12-20 20:41:42 +01:00
|
|
|
* Update a/an <%= subId || id %> entry.
|
2016-03-18 11:12:50 +01:00
|
|
|
*
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
|
2016-11-28 11:34:05 +01:00
|
|
|
update: async (ctx, next) => {
|
2016-03-18 11:12:50 +01:00
|
|
|
try {
|
2016-12-20 20:41:42 +01:00
|
|
|
ctx.body = await strapi.services.<%= subId || id %>.edit(ctx.params, ctx.request.body) ;
|
2016-03-18 11:12:50 +01:00
|
|
|
} catch (err) {
|
2016-11-28 11:34:05 +01:00
|
|
|
ctx.body = err;
|
2016-03-18 11:12:50 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-12-20 20:41:42 +01:00
|
|
|
* Destroy a/an <%= subId || id %> entry.
|
2016-03-18 11:12:50 +01:00
|
|
|
*
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
|
2016-11-28 11:34:05 +01:00
|
|
|
destroy: async (ctx, next) => {
|
2016-03-18 11:12:50 +01:00
|
|
|
try {
|
2016-12-20 20:41:42 +01:00
|
|
|
ctx.body = await strapi.services.<%= subId || id %>.remove(ctx.params);
|
2016-03-18 11:12:50 +01:00
|
|
|
} catch (err) {
|
2016-11-28 11:34:05 +01:00
|
|
|
ctx.body = err;
|
2016-03-18 11:12:50 +01:00
|
|
|
}
|
2016-12-20 20:41:42 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2016-03-18 11:12:50 +01:00
|
|
|
}
|
|
|
|
};
|