Код: Выделить всё
'use strict';
/**
* team controller
*/
const {createCoreController} = require('@strapi/strapi').factories;
module.exports = createCoreController('api::team.team', ({strapi}) => ({
async create(ctx) {
try {
const user = ctx.state.user;
if (!user) {
return ctx.unauthorized('You must be logged in to create a team');
}
const teamData = {
...ctx.request.body.data,
user: user.id
}
const team = await strapi.entityService.create('api::team.team', {
data: teamData,
});
return ctx.created(team);
} catch (error) {
throw ctx.throw(500, error);
}
},
async findOne(ctx) {
const {data, meta} = await super.findOne(ctx);
return {data, meta};
}
}));
Заранее спасибо за полезный ввод.
Подробнее здесь: https://stackoverflow.com/questions/794 ... lt-actions