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
|
||||||
@@ -65,5 +66,13 @@ module.exports = createCoreService('api::parole.parole', ({strapi}) => ({
|
|||||||
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