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}
|
|
|
|
*/
|
|
|
|
|
2016-12-02 12:28:20 +01:00
|
|
|
find: async (ctx, next) => {
|
2016-03-18 11:12:50 +01:00
|
|
|
try {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.body = await strapi.services.<%= id %>.fetchAll(ctx.query);
|
2016-03-18 11:12:50 +01:00
|
|
|
} catch (err) {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.body = err;
|
2016-03-18 11:12:50 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a specific <%= id %>.
|
|
|
|
*
|
|
|
|
* @return {Object|Array}
|
|
|
|
*/
|
|
|
|
|
2016-12-02 12:28:20 +01:00
|
|
|
findOne: async (ctx, next) => {
|
2016-03-18 11:12:50 +01:00
|
|
|
try {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.body = await strapi.services.<%= id %>.fetch(ctx.params)
|
2016-03-18 11:12:50 +01:00
|
|
|
} catch (err) {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.body = err;
|
2016-03-18 11:12:50 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a/an <%= id %> entry.
|
|
|
|
*
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
|
2016-12-02 12:28:20 +01:00
|
|
|
create: async (ctx, next) => {
|
2016-03-18 11:12:50 +01:00
|
|
|
try {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.body = await strapi.services.<%= id %>.add(ctx.request.body);
|
2016-03-18 11:12:50 +01:00
|
|
|
} catch (err) {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.body = err;
|
2016-03-18 11:12:50 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a/an <%= id %> entry.
|
|
|
|
*
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
|
2016-12-02 12:28:20 +01:00
|
|
|
update: async (ctx, next) => {
|
2016-03-18 11:12:50 +01:00
|
|
|
try {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.body = await strapi.services.<%= id %>.edit(ctx.params, ctx.request.body) ;
|
2016-03-18 11:12:50 +01:00
|
|
|
} catch (err) {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.body = err;
|
2016-03-18 11:12:50 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy a/an <%= id %> entry.
|
|
|
|
*
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
|
2016-12-02 12:28:20 +01:00
|
|
|
destroy: async (ctx, next) => {
|
2016-03-18 11:12:50 +01:00
|
|
|
try {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.body = await strapi.services.<%= id %>.remove(ctx.params);
|
2016-03-18 11:12:50 +01:00
|
|
|
} catch (err) {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.body = err;
|
2016-03-18 11:12:50 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add relation to a specific <%= id %>.
|
|
|
|
*
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
|
2016-12-02 12:28:20 +01:00
|
|
|
createRelation: async (ctx, next) => {
|
2016-03-18 11:12:50 +01:00
|
|
|
try {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.body = await strapi.services.<%= id %>.addRelation(ctx.params, ctx.request.body);
|
2016-03-18 11:12:50 +01:00
|
|
|
} catch (err) {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = err;
|
2016-03-18 11:12:50 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-03-22 15:50:33 +01:00
|
|
|
/**
|
|
|
|
* Update relation to a specific <%= id %>.
|
|
|
|
*
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
|
2016-12-02 12:28:20 +01:00
|
|
|
updateRelation: async (ctx, next) => {
|
2016-03-22 15:50:33 +01:00
|
|
|
try {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.body = await strapi.services.<%= id %>.editRelation(ctx.params, ctx.request.body);
|
2016-03-22 15:50:33 +01:00
|
|
|
} catch (err) {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = err;
|
2016-03-22 15:50:33 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-03-18 11:12:50 +01:00
|
|
|
/**
|
|
|
|
* Destroy relation to a specific <%= id %>.
|
|
|
|
*
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
|
2016-12-02 12:28:20 +01:00
|
|
|
destroyRelation: async (ctx, next) => {
|
2016-03-18 11:12:50 +01:00
|
|
|
try {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.body = await strapi.services.<%= id %>.removeRelation(ctx.params, ctx.request.body);
|
2016-03-18 11:12:50 +01:00
|
|
|
} catch (err) {
|
2016-12-02 12:28:20 +01:00
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = err;
|
2016-03-18 11:12:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|