Create parolesDiff service
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
const qs = require('qs')
|
||||
const axios = require('axios')
|
||||
const Diff = require('diff')
|
||||
|
||||
const { createCoreService } = require('@strapi/strapi').factories;
|
||||
const { ValidationError } = require("@strapi/utils").errors
|
||||
@@ -44,7 +45,7 @@ module.exports = createCoreService('api::parole.parole', ({strapi}) => ({
|
||||
const espagnol = await this.translate('FR', 'ES', parolesFR)
|
||||
const allemand = await this.translate('FR', 'DE', parolesFR)
|
||||
const italien = await this.translate('FR', 'IT', parolesFR)
|
||||
|
||||
|
||||
return {
|
||||
francais: parolesFR,
|
||||
anglais: anglais + '\n\n (Translated by DeepL)',
|
||||
@@ -57,13 +58,21 @@ module.exports = createCoreService('api::parole.parole', ({strapi}) => ({
|
||||
if (!titre || titre.trim().length === 0) {
|
||||
throw new ValidationError('Champ obligatoire. Veuillez choisir un titre.');
|
||||
}
|
||||
|
||||
|
||||
if (!transcription || transcription.trim().length === 0) {
|
||||
throw new ValidationError('Champ obligatoire. Veuillez renseigner la transcription.')
|
||||
}
|
||||
|
||||
|
||||
if (transcription.trim().length < 10) {
|
||||
throw new ValidationError('La transcription doit contenir au moins 10 caractères.')
|
||||
}
|
||||
},
|
||||
parolesDiff(titre = '', oldString, newString) {
|
||||
const patch = Diff.createPatch(titre, oldString, newString, 'supprimée', 'ajoutée')
|
||||
const parsePatch = Diff.parsePatch(patch)
|
||||
|
||||
if (parsePatch[0].hunks.length > 0) {
|
||||
return patch
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user