Rename awtis to artistes
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
'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('paroles').find({id_in: data})
|
||||
return teks
|
||||
}
|
||||
|
||||
const jwennAwtisEpiId = async id => {
|
||||
const artiste = await strapi.query('artiste').find({id})
|
||||
return artiste
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
beforeUpdate: async event => {
|
||||
let {data} = event
|
||||
|
||||
if (!data.slug) {
|
||||
data.slug = slugify(data.alias, {lower: true, remove: /[*#+~.()'"!:@]/g})
|
||||
}
|
||||
},
|
||||
beforeCreate: async event => {
|
||||
let {data} = event
|
||||
|
||||
data.slug = slugify(data.alias, {lower: true, remove: /[*#+~.()'"!:@]/g})
|
||||
},
|
||||
afterUpdate: async event => {
|
||||
let {data} = event
|
||||
const {id} = data
|
||||
const artiste = await jwennAwtisEpiId(id)
|
||||
|
||||
if (artiste.teks && artiste.paroles.length >= 1) {
|
||||
const paroles = await jwennTeksEpiId(artiste.paroles)
|
||||
Promise.all(paroles.map(async t => {
|
||||
const {id, tit, slug, artiste} = t
|
||||
const alias = artiste.map(a => a.alias).join('-')
|
||||
const slugUpdated = slugify(`${alias}-${tit}`, {lower: true, remove: /[*#+~.()'"!:@]/g})
|
||||
if (slug !== slugUpdated) {
|
||||
await strapi.query('paroles').update(
|
||||
{id},
|
||||
{slug: slugUpdated}
|
||||
)
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"kind": "collectionType",
|
||||
"collectionName": "artistes",
|
||||
"info": {
|
||||
"singularName": "artiste",
|
||||
"pluralName": "artistes",
|
||||
"displayName": "Artistes",
|
||||
"description": ""
|
||||
},
|
||||
"options": {
|
||||
"draftAndPublish": true
|
||||
},
|
||||
"pluginOptions": {},
|
||||
"attributes": {
|
||||
"alias": {
|
||||
"type": "string"
|
||||
},
|
||||
"prenon": {
|
||||
"type": "string"
|
||||
},
|
||||
"non": {
|
||||
"type": "string"
|
||||
},
|
||||
"biyografi": {
|
||||
"type": "richtext"
|
||||
},
|
||||
"nesans": {
|
||||
"type": "date"
|
||||
},
|
||||
"slug": {
|
||||
"type": "string"
|
||||
},
|
||||
"paroles": {
|
||||
"type": "relation",
|
||||
"relation": "manyToMany",
|
||||
"target": "api::parole.parole",
|
||||
"inversedBy": "artistes"
|
||||
},
|
||||
"admin_user": {
|
||||
"type": "relation",
|
||||
"relation": "oneToOne",
|
||||
"target": "admin::user"
|
||||
},
|
||||
"user": {
|
||||
"type": "relation",
|
||||
"relation": "oneToOne",
|
||||
"target": "plugin::users-permissions.user"
|
||||
},
|
||||
"foto": {
|
||||
"allowedTypes": [
|
||||
"images"
|
||||
],
|
||||
"type": "media",
|
||||
"multiple": false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { createCoreController } = require('@strapi/strapi').factories;
|
||||
|
||||
module.exports = createCoreController('api::artiste.artiste')
|
||||
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { createCoreRouter } = require('@strapi/strapi').factories;
|
||||
|
||||
module.exports = createCoreRouter('api::artiste.artiste')
|
||||
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { createCoreService } = require('@strapi/strapi').factories;
|
||||
|
||||
module.exports = createCoreService('api::artiste.artiste');
|
||||
Reference in New Issue
Block a user