Update article with date string
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
const { format } = require("date-fns");
|
||||
const { fr } = require("date-fns/locale");
|
||||
|
||||
module.exports = {
|
||||
async afterUpdate(event) {
|
||||
const { result, params } = event;
|
||||
const { data } = event.params;
|
||||
|
||||
const formattedDate = format(new Date(result.publishedAt), 'PPPP', { locale: fr });
|
||||
|
||||
if (result.date !== formattedDate) {
|
||||
await strapi.entityService.update('api::article.article', result.id, {
|
||||
data: {
|
||||
date: formattedDate,
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user