Update generated controller for Bookshelf's API

This commit is contained in:
Aurélien Georget 2016-12-02 12:28:20 +01:00
parent 76b12e9759
commit 83ff64737a

View File

@ -11,11 +11,11 @@ module.exports = {
* @return {Object|Array} * @return {Object|Array}
*/ */
find: function * () { find: async (ctx, next) => {
try { try {
this.body = yield strapi.services.<%= id %>.fetchAll(this.query); ctx.body = await strapi.services.<%= id %>.fetchAll(ctx.query);
} catch (err) { } catch (err) {
this.body = err; ctx.body = err;
} }
}, },
@ -25,11 +25,11 @@ module.exports = {
* @return {Object|Array} * @return {Object|Array}
*/ */
findOne: function * () { findOne: async (ctx, next) => {
try { try {
this.body = yield strapi.services.<%= id %>.fetch(this.params) ctx.body = await strapi.services.<%= id %>.fetch(ctx.params)
} catch (err) { } catch (err) {
this.body = err; ctx.body = err;
} }
}, },
@ -39,11 +39,11 @@ module.exports = {
* @return {Object} * @return {Object}
*/ */
create: function * () { create: async (ctx, next) => {
try { try {
this.body = yield strapi.services.<%= id %>.add(this.request.body); ctx.body = await strapi.services.<%= id %>.add(ctx.request.body);
} catch (err) { } catch (err) {
this.body = err; ctx.body = err;
} }
}, },
@ -53,11 +53,11 @@ module.exports = {
* @return {Object} * @return {Object}
*/ */
update: function * () { update: async (ctx, next) => {
try { try {
this.body = yield strapi.services.<%= id %>.edit(this.params, this.request.body) ; ctx.body = await strapi.services.<%= id %>.edit(ctx.params, ctx.request.body) ;
} catch (err) { } catch (err) {
this.body = err; ctx.body = err;
} }
}, },
@ -67,11 +67,11 @@ module.exports = {
* @return {Object} * @return {Object}
*/ */
destroy: function * () { destroy: async (ctx, next) => {
try { try {
this.body = yield strapi.services.<%= id %>.remove(this.params); ctx.body = await strapi.services.<%= id %>.remove(ctx.params);
} catch (err) { } catch (err) {
this.body = err; ctx.body = err;
} }
}, },
@ -81,12 +81,12 @@ module.exports = {
* @return {Object} * @return {Object}
*/ */
createRelation: function * () { createRelation: async (ctx, next) => {
try { try {
this.body = yield strapi.services.<%= id %>.addRelation(this.params, this.request.body); ctx.body = await strapi.services.<%= id %>.addRelation(ctx.params, ctx.request.body);
} catch (err) { } catch (err) {
this.status = 400; ctx.status = 400;
this.body = err; ctx.body = err;
} }
}, },
@ -96,12 +96,12 @@ module.exports = {
* @return {Object} * @return {Object}
*/ */
updateRelation: function * () { updateRelation: async (ctx, next) => {
try { try {
this.body = yield strapi.services.<%= id %>.editRelation(this.params, this.request.body); ctx.body = await strapi.services.<%= id %>.editRelation(ctx.params, ctx.request.body);
} catch (err) { } catch (err) {
this.status = 400; ctx.status = 400;
this.body = err; ctx.body = err;
} }
}, },
@ -111,12 +111,12 @@ module.exports = {
* @return {Object} * @return {Object}
*/ */
destroyRelation: function * () { destroyRelation: async (ctx, next) => {
try { try {
this.body = yield strapi.services.<%= id %>.removeRelation(this.params, this.request.body); ctx.body = await strapi.services.<%= id %>.removeRelation(ctx.params, ctx.request.body);
} catch (err) { } catch (err) {
this.status = 400; ctx.status = 400;
this.body = err; ctx.body = err;
} }
} }
}; };