feat: backfiller le catalogue existant, une parole/heure
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
const bokanteMastodon = require('./bokante-mastodon');
|
||||
|
||||
async function backfillBokanteMirror({strapi}) {
|
||||
const [parole] = await strapi.db.query('api::parole.parole').findMany({
|
||||
where: {
|
||||
publishedAt: {$notNull: true},
|
||||
bokanteStatusId: {$null: true}
|
||||
},
|
||||
orderBy: {publishedAt: 'asc'},
|
||||
limit: 1
|
||||
});
|
||||
|
||||
if (!parole) {
|
||||
return {backfilled: false};
|
||||
}
|
||||
|
||||
try {
|
||||
const status = await bokanteMastodon.createStatus(
|
||||
`"${parole.titre}" — à (re)découvrir sur pawol.nu\n${process.env.WEBSITE_URL}/paroles/${parole.slug}`
|
||||
);
|
||||
|
||||
await strapi.db.query('api::parole.parole').updateMany({
|
||||
where: {documentId: parole.documentId},
|
||||
data: {bokanteStatusId: status.id}
|
||||
});
|
||||
|
||||
return {backfilled: true, slug: parole.slug};
|
||||
} catch (err) {
|
||||
strapi.log.error(`Backfill bokante (${parole.slug}) : ${err.message}`);
|
||||
return {backfilled: false};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {backfillBokanteMirror};
|
||||
Reference in New Issue
Block a user