Skip to content

Commit

Permalink
fix bug status conflict in exec publication
Browse files Browse the repository at this point in the history
  • Loading branch information
fufeck committed Jan 15, 2024
1 parent dae48d2 commit 931ec28
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
8 changes: 4 additions & 4 deletions apps/api/src/modules/base_locale/base_locale.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class BaseLocaleService {
const updatedBaseLocale = await this.baseLocaleModel.findOneAndUpdate(
{ _id: baseLocale._id },
{ $set: update },
{ returnDocument: 'after' },
{ new: true },
);

// If emails fields is overrided, we compare with current array to send a notification to new email addresses
Expand Down Expand Up @@ -246,7 +246,7 @@ export class BaseLocaleService {
status: StatusBaseLocalEnum.DRAFT,
},
},
{ returnDocument: 'after' },
{ new: true },
);

const templateEmail = createBalCreationNotificationEmail({
Expand Down Expand Up @@ -419,7 +419,7 @@ export class BaseLocaleService {
const recoveredBaseLocale = await this.baseLocaleModel.findByIdAndUpdate(
{ _id: baseLocale._id },
{ $set: { _deleted: null, _updated: now } },
{ returnDocument: 'after' },
{ new: true },
);

return recoveredBaseLocale;
Expand All @@ -430,7 +430,7 @@ export class BaseLocaleService {
const updatedBaseLocale = await this.baseLocaleModel.findByIdAndUpdate(
{ _id: baseLocale._id },
{ $set: { token } },
{ returnDocument: 'after' },
{ new: true },
);

const email = createTokenRenewalNotificationEmail({
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/modules/numeros/numero.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export class NumeroService {
const numeroUpdated: Numero = await this.numeroModel.findOneAndUpdate(
{ _id: numero._id, _deleted: null },
{ $set: { ...updateNumeroDto, _updated: new Date() } },
{ returnDocument: 'after' },
{ new: true },
);

if (numeroUpdated) {
Expand Down Expand Up @@ -273,7 +273,7 @@ export class NumeroService {
const numeroUpdated: Numero = await this.numeroModel.findOneAndUpdate(
{ _id: numero._id },
{ $set: { _deleted: new Date() } },
{ returnDocument: 'after' },
{ new: true },
);

// UPDATE TILES VOIE
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/modules/toponyme/toponyme.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class ToponymeService {
const toponymeUpdated = await this.toponymeModel.findOneAndUpdate(
{ _id: toponyme._id, _deleted: null },
{ $set: { ...updateToponymeDto, _updated: new Date() } },
{ returnDocument: 'after' },
{ new: true },
);

// SET _updated BAL
Expand All @@ -156,7 +156,7 @@ export class ToponymeService {
const toponymeUpdated: Toponyme = await this.toponymeModel.findOneAndUpdate(
{ _id: toponyme._id },
{ $set: { _deleted: new Date(), _updated: new Date() } },
{ returnDocument: 'after' },
{ new: true },
);

await this.numeroService.updateMany(
Expand All @@ -176,7 +176,7 @@ export class ToponymeService {
const updatedToponyme = await this.toponymeModel.findOneAndUpdate(
{ _id: toponyme._id },
{ $set: { _deleted: null, _updated: new Date() } },
{ returnDocument: 'after' },
{ new: true },
);
// SET _updated OF TOPONYME
await this.baseLocaleService.touch(toponyme._bal);
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/modules/voie/voie.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export class VoieService {
const voieUpdated: Voie = await this.voieModel.findOneAndUpdate(
{ _id: voie._id },
{ $set: { _deleted: new Date(), _updated: new Date() } },
{ returnDocument: 'after' },
{ new: true },
);

// SET _updated OF VOIE
Expand Down
20 changes: 9 additions & 11 deletions libs/shared/src/modules/publication/publication.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model, Types } from 'mongoose';
import * as hasha from 'hasha';
import { assignIn } from 'lodash';

import {
Habilitation,
Expand Down Expand Up @@ -171,7 +172,7 @@ export class PublicationService {
},
},
{ $set: { 'sync.isPaused': isPaused } },
{ returnDocument: 'after' },
{ new: true },
);

if (!baseLocale) {
Expand All @@ -188,21 +189,19 @@ export class PublicationService {
baseLocale: BaseLocale,
syncChanges: Partial<Sync>,
): Promise<Sync> {
const sync: Sync = baseLocale.sync;
assignIn(sync, syncChanges);
const changes: Partial<BaseLocale> = {
sync: {
...baseLocale.sync,
...syncChanges,
},
sync,
...(syncChanges.status === 'conflict' && {
status: StatusBaseLocalEnum.REPLACED,
}),
};

const baseLocaleChanged: BaseLocale =
await this.baseLocaleModel.findOneAndUpdate(
{ _id: baseLocale._id },
{ $set: changes },
{ returnDocument: 'after' },
{ new: true },
);

return baseLocaleChanged.sync;
Expand All @@ -223,7 +222,7 @@ export class PublicationService {
await this.baseLocaleModel.findOneAndUpdate(
{ _id: baseLocale._id },
{ $set: { status: StatusBaseLocalEnum.PUBLISHED, sync } },
{ returnDocument: 'after' },
{ new: true },
);

return baseLocaleSynced;
Expand Down Expand Up @@ -257,8 +256,7 @@ export class PublicationService {

// On vérifie si la dernière publication de la BAL est la révision courante
if (
new Types.ObjectId(currentRevision?._id) !==
baseLocale.sync.lastUploadedRevisionId
currentRevision?._id !== baseLocale.sync.lastUploadedRevisionId.toString()
) {
return this.updateSync(baseLocale, {
status: StatusSyncEnum.CONFLICT,
Expand All @@ -268,7 +266,7 @@ export class PublicationService {

// Si la date du changement de BAL est la même que la date du currentUpdated du sync de la BAL
// On met le status du sync de la BAL a sync et on le retourne
// ???

if (baseLocale._updated === baseLocale.sync.currentUpdated) {
if (baseLocale.sync.status === StatusSyncEnum.SYNCED) {
return baseLocale.sync;
Expand Down

0 comments on commit 931ec28

Please sign in to comment.