Created
July 22, 2020 10:46
-
-
Save haikyuu/361730d4246ccd62736bc2c513361e40 to your computer and use it in GitHub Desktop.
Strapi extend controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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