2020-12-06 22:13:45 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
2021-05-23 21:18:11 +02:00
|
|
|
const {default: createStrapi} = require('strapi');
|
|
|
|
|
const {parseMultipartData, sanitizeEntity} = require('strapi-utils')
|
|
|
|
|
|
2020-12-06 22:13:45 +01:00
|
|
|
/**
|
|
|
|
|
* Read the documentation (https://strapi.io/documentation/v3.x/concepts/controllers.html#core-controllers)
|
|
|
|
|
* to customize this controller
|
|
|
|
|
*/
|
|
|
|
|
|
2021-05-24 02:41:55 +02:00
|
|
|
const searchAwtis = async alias => {
|
|
|
|
|
const awtis = await strapi.query('awtis').findOne({alias: alias.trim()})
|
|
|
|
|
return awtis
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-23 21:18:11 +02:00
|
|
|
module.exports = {
|
|
|
|
|
async create(ctx) {
|
|
|
|
|
let entity
|
|
|
|
|
if (ctx.is('multipart')) {
|
|
|
|
|
let {data} = parseMultipartData(ctx)
|
2021-05-24 02:41:55 +02:00
|
|
|
const awtis = await searchAwtis(data.alias)
|
|
|
|
|
if (awtis) {
|
2022-05-05 20:20:00 +04:00
|
|
|
entity = await strapi.services.awtis.update({id: awtis.id}, awtis)
|
2021-05-24 02:41:55 +02:00
|
|
|
} else {
|
|
|
|
|
data.published_at = null
|
|
|
|
|
entity = await createStrapi.services.awtis.create(data)
|
|
|
|
|
}
|
2021-05-23 21:18:11 +02:00
|
|
|
} else {
|
|
|
|
|
let {body} = ctx.request
|
2021-05-24 02:41:55 +02:00
|
|
|
const awtis = await searchAwtis(body.alias)
|
|
|
|
|
if (awtis) {
|
2022-05-05 20:20:00 +04:00
|
|
|
entity = await strapi.services.awtis.update({id: awtis.id}, awtis)
|
2021-05-24 02:41:55 +02:00
|
|
|
} else {
|
|
|
|
|
body.published_at = null
|
|
|
|
|
entity = await strapi.services.awtis.create(body)
|
|
|
|
|
}
|
2021-05-23 21:18:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sanitizeEntity(entity, {model: strapi.models.awtis})
|
|
|
|
|
}
|
|
|
|
|
}
|