From c7b1b06d0a055018d076ceb6915039f5cc8bd834 Mon Sep 17 00:00:00 2001 From: cmoinier Date: Thu, 19 Dec 2024 16:33:45 +0100 Subject: [PATCH] fix: change facade fn name, return undefined values if not changed --- .../src/lib/gn4/gn4-repository.spec.ts | 13 -------- .../repository/src/lib/gn4/gn4-repository.ts | 30 +++++++------------ .../editor/src/lib/+state/editor.facade.ts | 2 +- 3 files changed, 12 insertions(+), 33 deletions(-) diff --git a/libs/api/repository/src/lib/gn4/gn4-repository.spec.ts b/libs/api/repository/src/lib/gn4/gn4-repository.spec.ts index 96ad006b1..25c33153e 100644 --- a/libs/api/repository/src/lib/gn4/gn4-repository.spec.ts +++ b/libs/api/repository/src/lib/gn4/gn4-repository.spec.ts @@ -841,17 +841,4 @@ describe('Gn4Repository', () => { }) }) }) - describe('formatDate', () => { - it('should format date correctly based on current language', () => { - const date = new Date('2024-01-01T10:00:00Z') - const formattedDate = repository.formatDate(date) - expect(formattedDate).toBe('1 janvier 2024 à 10:00') - }) - - it('should handle invalid date gracefully', () => { - const invalidDate = new Date('invalid-date') - const formattedDate = repository.formatDate(invalidDate) - expect(formattedDate).toBe('Invalid Date') - }) - }) }) diff --git a/libs/api/repository/src/lib/gn4/gn4-repository.ts b/libs/api/repository/src/lib/gn4/gn4-repository.ts index 0abbe665e..0553c1df6 100644 --- a/libs/api/repository/src/lib/gn4/gn4-repository.ts +++ b/libs/api/repository/src/lib/gn4/gn4-repository.ts @@ -41,7 +41,6 @@ import { import { catchError, map, tap } from 'rxjs/operators' import { lt } from 'semver' import { ElasticsearchService } from './elasticsearch' -import { TranslateService } from '@ngx-translate/core' const minPublicationApiVersion = '4.2.5' @@ -60,8 +59,7 @@ export class Gn4Repository implements RecordsRepositoryInterface { private gn4SearchHelper: ElasticsearchService, private gn4Mapper: Gn4Converter, private gn4RecordsApi: RecordsApiService, - private platformService: PlatformServiceInterface, - private translateService: TranslateService + private platformService: PlatformServiceInterface ) {} search({ @@ -372,7 +370,7 @@ export class Gn4Repository implements RecordsRepositoryInterface { const hasDraft = this.recordHasDraft(localRecord.uniqueIdentifier) if (isUnsaved || !hasDraft) { - return of([]) + return of(null) } return combineLatest([ @@ -388,26 +386,20 @@ export class Gn4Repository implements RecordsRepositoryInterface { ]).pipe( map(([draftRecordUpdated, recentRecord]) => { if (recentRecord.recordUpdated > draftRecordUpdated) { - return [ - this.formatDate(recentRecord.recordUpdated), - recentRecord.extras?.['ownerInfo'].toString().split('|')[0], - ] + const user = recentRecord.extras?.['ownerInfo'].toString().split('|') + return { + user: `${user[2]} ${user[1]}`, + date: recentRecord.recordUpdated, + } + } + return { + user: undefined, + date: undefined, } - return [] }) ) } - formatDate(date: Date): string { - return date.toLocaleDateString(this.translateService.currentLang, { - year: 'numeric', - month: 'long', - day: 'numeric', - hour: 'numeric', - minute: 'numeric', - }) - } - private getRecordAsXml(uniqueIdentifier: string): Observable { return this.gn4RecordsApi .getRecordAs( diff --git a/libs/feature/editor/src/lib/+state/editor.facade.ts b/libs/feature/editor/src/lib/+state/editor.facade.ts index e384a875b..2c6e0400e 100644 --- a/libs/feature/editor/src/lib/+state/editor.facade.ts +++ b/libs/feature/editor/src/lib/+state/editor.facade.ts @@ -67,7 +67,7 @@ export class EditorFacade { this.store.dispatch(EditorActions.setFieldVisibility({ field, visible })) } - hasRecordChangedSinceDraft(record: CatalogRecord) { + checkHasRecordChanged(record: CatalogRecord) { this.store.dispatch(EditorActions.hasRecordChangedSinceDraft({ record })) } }