Add difference when updating transcription
This commit is contained in:
@@ -131,8 +131,21 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
beforeUpdate: async event => {
|
||||
const {state} = event
|
||||
let {data} = event.params
|
||||
const {where} = event.params
|
||||
const {id} = where
|
||||
|
||||
const previousParoles = await strapi.db.query('api::parole.parole').findOne({
|
||||
where: {id},
|
||||
populate: {difference: true}
|
||||
})
|
||||
|
||||
if (data.transcription) {
|
||||
const difference = strapi.service('api::parole.parole').parolesDiff(data.titre, previousParoles.transcription, data.transcription)
|
||||
|
||||
state.diff = difference
|
||||
}
|
||||
|
||||
if(!data.publishedAt && data.titre && data.transcription) {
|
||||
strapi.service('api::parole.parole').validateParoles(data.titre, data.transcription)
|
||||
@@ -184,6 +197,24 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
},
|
||||
afterUpdate: async event => {
|
||||
const {result, state} = event
|
||||
|
||||
if (state.diff) {
|
||||
await strapi.entityService.update('api::parole.parole', result.id, {
|
||||
data: {
|
||||
difference: [
|
||||
...result.difference,
|
||||
{
|
||||
admin_user: result.updatedBy.id,
|
||||
paroles: state.diff,
|
||||
date: new Date(),
|
||||
sources: 'transcription'
|
||||
}]
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
afterCreate: async event => {
|
||||
const {data} = event.params
|
||||
const user = await jwennUserEpiId(data?.user?.id)
|
||||
|
||||
Reference in New Issue
Block a user