Skip to content

Commit

Permalink
updateMany waiting-habilitation
Browse files Browse the repository at this point in the history
  • Loading branch information
fufeck committed Nov 29, 2023
1 parent 89a5344 commit 9a54573
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions apps/cron/src/tasks/sync_outdated.task.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Injectable, Logger } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model, Types } from 'mongoose';
import { sub } from 'date-fns';

import { BaseLocale } from '@/shared/schemas/base_locale/base_locale.schema';
import {
Expand Down Expand Up @@ -31,20 +30,24 @@ export class SyncOutdatedTask implements Task {
{ 'sync.status': StatusSyncEnum.OUTDATED },
);

const noHabilitationBalIds: Types.ObjectId[] = [];
for (const balId of idsToSync) {
try {
await this.publicationService.exec(balId);
} catch (error) {
if (error.cause === BAD_HABILITATION) {
await this.baseLocaleModel.updateOne({
_id: balId,
status: StatusBaseLocalEnum.WAITING_HABILITATION,
});
noHabilitationBalIds.push(balId);
} else {
this.logger.error(`Unable to sync ${balId}`);
this.logger.error(error);
}
}
}
if (noHabilitationBalIds.length > 0) {
await this.baseLocaleModel.updateMany(
{ _id: { $in: noHabilitationBalIds } },
{ status: StatusBaseLocalEnum.WAITING_HABILITATION },
);
}
}
}

0 comments on commit 9a54573

Please sign in to comment.