Skip to content

Instantly share code, notes, and snippets.

@GalloDaSballo
Created January 16, 2020 21:23
Show Gist options
  • Save GalloDaSballo/202cd2296a0bd4126b989d414d87a176 to your computer and use it in GitHub Desktop.
Save GalloDaSballo/202cd2296a0bd4126b989d414d87a176 to your computer and use it in GitHub Desktop.
//Overridden strapi article controller file
'use strict';
//Controllers
const { parseMultipartData, sanitizeEntity } = require('strapi-utils');
/**
* Read the documentation (https://strapi.io/documentation/3.0.0-beta.x/concepts/controllers.html#core-controllers)
* to customize this controller
*/
module.exports = {
/**
* Create a record.
*
* @return {Object}
*/
async create(ctx) {
console.log("api/controllers/article.create strapi.services", strapi.services)
console.log("api/controllers/article.create strapi.controllers", strapi.controllers)
console.log("api/controllers/article.create strapi.models", strapi.models)
console.log("api/controllers/article.create ctx.state.user", ctx.state.user)
const { id } = ctx.state.user
const {title, content} = ctx.request.body
const article = {
title,
content,
user: id
}
let entity;
if (ctx.is('multipart')) {
console.log("api/controllers/article.create we do not allow multipart")
entity = null
} else {
entity = await strapi.services.article.create(article);
}
return sanitizeEntity(entity, { model: strapi.models.article });
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment