Changes from codemod

This commit is contained in:
2026-04-21 21:35:59 +04:00
parent e7bc8790b1
commit b532981404
8 changed files with 689 additions and 569 deletions
@@ -1,10 +1,5 @@
'use strict';
/**
* Read the documentation (https://strapi.io/documentation/v3.x/concepts/models.html#lifecycle-hooks)
* to customize this model
*/
const { ApplicationError } = require("@strapi/utils").errors
const slugify = require('slugify')
+4 -2
View File
@@ -26,7 +26,9 @@ module.exports = createCoreController('api::artiste.artiste', ({strapi}) => ({
}
}
const user = await strapi.entityService.findOne('plugin::users-permissions.user', body.data.user.id)
const user = await strapi.documents('plugin::users-permissions.user').findOne({
documentId: "__TODO__"
})
if (!user) {
throw new NotFoundError('Utilisateur introuvable.')
@@ -43,7 +45,7 @@ module.exports = createCoreController('api::artiste.artiste', ({strapi}) => ({
if (artiste) {
return artiste
} else {
const newArtiste = await strapi.entityService.create('api::artiste.artiste', {
const newArtiste = await strapi.documents('api::artiste.artiste').create({
data: {
...data
}
@@ -21,7 +21,9 @@ module.exports = createCoreController('api::commentaire.commentaire', ({strapi})
throw new UnauthorizedError(ctx, err, 'Opération non autorisée')
}
}
const user = await strapi.entityService.findOne('plugin::users-permissions.user', body.data.user.id)
const user = await strapi.documents('plugin::users-permissions.user').findOne({
documentId: "__TODO__"
})
if (!user) {
throw new NotFoundError('Utilisateur introuvable.')
@@ -33,7 +35,8 @@ module.exports = createCoreController('api::commentaire.commentaire', ({strapi})
data.user = user.id
const parole = await strapi.entityService.findOne('api::parole.parole', data.parole, {
const parole = await strapi.documents('api::parole.parole').findOne({
documentId: "__TODO__",
fields: ['id']
})
@@ -41,13 +44,15 @@ module.exports = createCoreController('api::commentaire.commentaire', ({strapi})
throw new NotFoundError('Texte introuvable.')
}
const newCommentaire = await strapi.entityService.create('api::commentaire.commentaire', {
const newCommentaire = await strapi.documents('api::commentaire.commentaire').create({
data: {
...data
}
})
await strapi.entityService.update('api::parole.parole', parole.id, {
await strapi.documents('api::parole.parole').update({
documentId: "__TODO__",
data: {
commentaires: [newCommentaire.id]
}
+16 -7
View File
@@ -5,7 +5,8 @@ const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::parole.parole', ({strapi}) => ({
async findOne(ctx) {
const {id} = ctx.params
const parole = await strapi.entityService.findOne('api::parole.parole', id, {
const parole = await strapi.documents('api::parole.parole').findOne({
documentId: "__TODO__",
populate: ['artistes']
})
return parole
@@ -14,7 +15,9 @@ module.exports = createCoreController('api::parole.parole', ({strapi}) => ({
const {body} = ctx.request
const {data} = body
const updatedParole = await strapi.entityService.update('api::parole.parole', data.id, {
const updatedParole = await strapi.documents('api::parole.parole').update({
documentId: "__TODO__",
data: {
...data
}
@@ -41,7 +44,9 @@ module.exports = createCoreController('api::parole.parole', ({strapi}) => ({
}
}
const user = await strapi.entityService.findOne('plugin::users-permissions.user', body.data.user.id)
const user = await strapi.documents('plugin::users-permissions.user').findOne({
documentId: "__TODO__"
})
if (!user) {
ctx.notFound('Utilisateur introuvable.')
@@ -51,13 +56,15 @@ module.exports = createCoreController('api::parole.parole', ({strapi}) => ({
ctx.badRequest('Informations non valides.')
}
const artiste = await strapi.entityService.findOne('api::artiste.artiste', data.artistes[0])
const artiste = await strapi.documents('api::artiste.artiste').findOne({
documentId: "__TODO__"
})
if (!artiste) {
ctx.notFound('Artiste introuvable.')
}
const currentUserParole = await strapi.entityService.findMany('api::parole.parole', {
const currentUserParole = await strapi.documents('api::parole.parole').findMany({
fields: ['id'],
filters: {
user: {
@@ -77,7 +84,7 @@ module.exports = createCoreController('api::parole.parole', ({strapi}) => ({
data.traductions = translated
}
const newParole = await strapi.entityService.create('api::parole.parole', {
const newParole = await strapi.documents('api::parole.parole').create({
data: {
...data
}
@@ -86,7 +93,9 @@ module.exports = createCoreController('api::parole.parole', ({strapi}) => ({
const parolesIds = currentUserParole.map(({id}) => id)
parolesIds.push(newParole.id)
await strapi.entityService.update('plugin::users-permissions.user', user.id, {
await strapi.documents('plugin::users-permissions.user').update({
documentId: "__TODO__",
data: {
paroles: parolesIds
}