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