Skip to content

Instantly share code, notes, and snippets.

@haikyuu
Created July 22, 2020 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haikyuu/361730d4246ccd62736bc2c513361e40 to your computer and use it in GitHub Desktop.
Save haikyuu/361730d4246ccd62736bc2c513361e40 to your computer and use it in GitHub Desktop.
Strapi extend controller
'use strict';
/**
* Read the documentation (https://strapi.io/documentation/v3.x/concepts/controllers.html#core-controllers)
* to customize this controller
*/
const { parseMultipartData, sanitizeEntity } = require('strapi-utils');
module.exports = {
async create(ctx) {
let entity;
if (ctx.is('multipart')) {
const { data, files } = parseMultipartData(ctx);
entity = await strapi.services.restaurant.create(data, { files });
} else {
entity = await strapi.services.restaurant.create(ctx.request.body);
}
return sanitizeEntity(entity, { model: strapi.models.restaurant });
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment