From 883d0fa108cef78da9b2c0be84580d8eccb888df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Sun, 23 May 2021 21:18:11 +0200 Subject: [PATCH] Force draft when submitting awtis & teks --- api/awtis/controllers/awtis.js | 20 +++++++++++++++++++- api/teks/controllers/teks.js | 20 +++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/api/awtis/controllers/awtis.js b/api/awtis/controllers/awtis.js index a589b84..17bdd12 100644 --- a/api/awtis/controllers/awtis.js +++ b/api/awtis/controllers/awtis.js @@ -1,8 +1,26 @@ 'use strict'; +const {default: createStrapi} = require('strapi'); +const {parseMultipartData, sanitizeEntity} = require('strapi-utils') + /** * Read the documentation (https://strapi.io/documentation/v3.x/concepts/controllers.html#core-controllers) * to customize this controller */ -module.exports = {}; +module.exports = { + async create(ctx) { + let entity + if (ctx.is('multipart')) { + let {data} = parseMultipartData(ctx) + data.published_at = null + entity = await createStrapi.services.awtis.create(data) + } else { + let {body} = ctx.request + body.published_at = null + entity = await strapi.services.awtis.create(body) + } + + return sanitizeEntity(entity, {model: strapi.models.awtis}) + } +} diff --git a/api/teks/controllers/teks.js b/api/teks/controllers/teks.js index a589b84..3f58187 100644 --- a/api/teks/controllers/teks.js +++ b/api/teks/controllers/teks.js @@ -1,8 +1,26 @@ 'use strict'; +const {default: createStrapi} = require('strapi'); +const {parseMultipartData, sanitizeEntity} = require('strapi-utils') + /** * Read the documentation (https://strapi.io/documentation/v3.x/concepts/controllers.html#core-controllers) * to customize this controller */ -module.exports = {}; + module.exports = { + async create(ctx) { + let entity + if (ctx.is('multipart')) { + let {data} = parseMultipartData(ctx) + data.published_at = null + entity = await createStrapi.services.teks.create(data) + } else { + let {body} = ctx.request + body.published_at = null + entity = await strapi.services.teks.create(body) + } + + return sanitizeEntity(entity, {model: strapi.models.teks}) + } +}