Skip to content

Commit

Permalink
fix: change facade fn name, return undefined values if not changed
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier committed Dec 19, 2024
1 parent 919fec5 commit c7b1b06
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 33 deletions.
13 changes: 0 additions & 13 deletions libs/api/repository/src/lib/gn4/gn4-repository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
})
30 changes: 11 additions & 19 deletions libs/api/repository/src/lib/gn4/gn4-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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({
Expand Down Expand Up @@ -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([
Expand All @@ -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<string | null> {
return this.gn4RecordsApi
.getRecordAs(
Expand Down
2 changes: 1 addition & 1 deletion libs/feature/editor/src/lib/+state/editor.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
}
}

0 comments on commit c7b1b06

Please sign in to comment.