Create Teks collection

This commit is contained in:
2020-12-18 19:23:21 +01:00
parent 1ba20a2003
commit 3ba187e602
6 changed files with 152 additions and 2 deletions
+25
View File
@@ -0,0 +1,25 @@
'use strict';
const slugify = require('slugify')
const jwennAwtisEpiId = async data => {
const awtis = await strapi.query('awtis').find({_id: data})
return awtis.map(a => a.alias).join('-')
}
module.exports = {
lifecycles: {
beforeCreate: async data => {
if (data.tit) {
const awtis = await jwennAwtisEpiId(data.awtis)
data.slug = slugify(`${awtis}-${data.tit}`, {lower: true, remove: /[*#+~.()'"!:@]/g})
}
},
beforeUpdate: async (params, data) => {
if (data.tit) {
const awtis = await jwennAwtisEpiId(data.awtis)
data.slug = slugify(`${awtis}-${data.tit}`, {lower: true, remove: /[*#+~.()'"!:@]/g})
}
}
}
}
+57
View File
@@ -0,0 +1,57 @@
{
"kind": "collectionType",
"collectionName": "teks",
"info": {
"name": "Teks",
"description": ""
},
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": true
},
"attributes": {
"tit": {
"type": "string",
"required": true
},
"transkripsyon": {
"type": "richtext"
},
"tradiksyon": {
"type": "component",
"repeatable": false,
"component": "trad.traductions"
},
"lanne": {
"type": "integer"
},
"lyen": {
"type": "component",
"repeatable": false,
"component": "url.liens"
},
"awtis": {
"via": "teks",
"collection": "awtis",
"dominant": true
},
"kouteyAchtey": {
"type": "component",
"repeatable": false,
"component": "store.store"
},
"slug": {
"type": "string"
},
"kouveti": {
"model": "file",
"via": "related",
"allowedTypes": [
"images"
],
"plugin": "upload",
"required": false
}
}
}