Move and update models to content-types

This commit is contained in:
Cédric FAMIBELLE-PRONZOLA
2022-05-12 04:20:00 +04:00
parent 2737770ff7
commit f08459ffad
9 changed files with 248 additions and 228 deletions
-50
View File
@@ -1,50 +0,0 @@
'use strict';
/**
* Read the documentation (https://strapi.io/documentation/v3.x/concepts/models.html#lifecycle-hooks)
* to customize this model
*/
const slugify = require('slugify')
const jwennTeksEpiId = async data => {
const teks = await strapi.query('teks').find({id_in: data})
return teks
}
const jwennAwtisEpiId = async id => {
const awtis = await strapi.query('awtis').find({id})
return awtis
}
module.exports = {
lifecycles: {
beforeUpdate: async (params, data) => {
if (!data.slug) {
data.slug = slugify(data.alias, {lower: true, remove: /[*#+~.()'"!:@]/g})
}
},
beforeCreate: async data => {
data.slug = slugify(data.alias, {lower: true, remove: /[*#+~.()'"!:@]/g})
},
afterUpdate: async (params, data) => {
const {id} = data
const awtis = await jwennAwtisEpiId(id)
if (awtis.teks && awtis.teks.length >= 1) {
const teks = await jwennTeksEpiId(awtis.teks)
Promise.all(teks.map(async t => {
const {id, tit, slug, awtis} = t
const alias = awtis.map(a => a.alias).join('-')
const slugUpdated = slugify(`${alias}-${tit}`, {lower: true, remove: /[*#+~.()'"!:@]/g})
if (slug !== slugUpdated) {
await strapi.query('teks').update(
{id},
{slug: slugUpdated}
)
}
}))
}
}
}
}
-53
View File
@@ -1,53 +0,0 @@
{
"kind": "collectionType",
"collectionName": "awtis",
"info": {
"name": "awtis",
"description": ""
},
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": true
},
"attributes": {
"alias": {
"type": "string",
"unique": true,
"required": true
},
"prenon": {
"type": "string"
},
"non": {
"type": "string"
},
"biyografi": {
"type": "richtext"
},
"nesans": {
"type": "date"
},
"foto": {
"collection": "file",
"via": "related",
"allowedTypes": [
"images"
],
"plugin": "upload",
"required": false,
"pluginOptions": {}
},
"teks": {
"via": "awtis",
"collection": "teks"
},
"user": {
"plugin": "users-permissions",
"model": "user"
},
"slug": {
"type": "string"
}
}
}