Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/app/core/services/edit/edit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,4 +662,21 @@ export class EditService {
});
});
}

public async updateStelaRecord(record: RecordVO): Promise<void> {
const originalValue = record.displayTimeInEDTF;
try {
const response = await this.api.record.updateStelaRecord(record);
const updatedRecord = response.getRecordVO();
if (updatedRecord) {
record.update({
updatedDT: updatedRecord.updatedDT,
});
}
} catch (err) {
if (err instanceof RecordResponse) {
record.update({ displayTimeInEDTF: originalValue });
}
}
}
}
2 changes: 2 additions & 0 deletions src/app/models/record-vo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class RecordVO
public description;
public displayDT;
public displayEndDT;
public displayTimeInEDTF;
public derivedDT;
public derivedEndDT;
public altText;
Expand Down Expand Up @@ -185,6 +186,7 @@ export interface RecordVOData extends BaseVOData {
description?: any;
displayDT?: any;
displayEndDT?: any;
displayTimeInEDTF?: any;
derivedDT?: any;
derivedEndDT?: any;
derivedCreatedDT?: any;
Expand Down
86 changes: 86 additions & 0 deletions src/app/shared/services/api/record.repo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,90 @@ describe('RecordRepo', () => {
expect(result).toEqual([]);
});
});

describe('updateStelaRecord', () => {
let httpV2PatchSpy: jasmine.Spy;
let httpSendRequestPromiseSpy: jasmine.Spy;

const fakeStelaRecord = {
recordId: 42,
displayName: 'Test Record',
archiveNumber: 'arch-1',
displayDate: '2025-01-01',
folderLinkId: '1',
folderLinkType: 'type.folder_link.private',
parentFolderLinkId: '2',
thumbUrl200: '',
thumbUrl500: '',
thumbUrl1000: '',
thumbUrl2000: '',
location: null,
files: [],
createdAt: '2025-01-01',
updatedAt: '2025-01-01',
archive: { id: '1', name: 'Archive', thumbURL200: '' },
shares: null,
tags: null,
};

beforeEach(() => {
httpV2PatchSpy = spyOn(httpV2Service, 'patch');
httpSendRequestPromiseSpy = spyOn(httpService, 'sendRequestPromise');
});

it('should send a PATCH request with displayTimeInEDTF', async () => {
const recordVO = new RecordVO({
recordId: 42,
displayTimeInEDTF: '1985-05-20',
});

httpV2PatchSpy.and.returnValue(of([fakeStelaRecord]));

const result = await repo.updateStelaRecord(recordVO);

expect(httpV2PatchSpy).toHaveBeenCalledWith('v2/records/42', {
displayTimeInEDTF: '1985-05-20',
});

expect(result).toBeInstanceOf(RecordResponse);
});

it('should look up recordId by archiveNbr when recordId is not available', async () => {
const recordVO = new RecordVO({
archiveNbr: 'archive-100',
displayTimeInEDTF: '2000-03',
});

httpSendRequestPromiseSpy.and.resolveTo({
getRecordVO: () => new RecordVO({ recordId: 99 }),
});
httpV2PatchSpy.and.returnValue(of([fakeStelaRecord]));

await repo.updateStelaRecord(recordVO);

expect(httpSendRequestPromiseSpy).toHaveBeenCalledWith(
'/record/get',
[{ RecordVO: jasmine.objectContaining({ archiveNbr: 'archive-100' }) }],
jasmine.any(Object),
);

expect(httpV2PatchSpy).toHaveBeenCalledWith('v2/records/99', {
displayTimeInEDTF: '2000-03',
});
});

it('should return a RecordResponse with converted record data', async () => {
const recordVO = new RecordVO({
recordId: 42,
displayTimeInEDTF: '1985-05',
});

httpV2PatchSpy.and.returnValue(of([fakeStelaRecord]));

const result = await repo.updateStelaRecord(recordVO);
const resultRecord = result.getRecordVO();

expect(resultRecord).toBeInstanceOf(RecordVO);
});
});
});
33 changes: 33 additions & 0 deletions src/app/shared/services/api/record.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,39 @@ export class RecordRepo extends BaseRepo {
);
}

public async updateStelaRecord(recordVO: RecordVO): Promise<RecordResponse> {
const recordId =
recordVO.recordId ??
(await this.getRecordIdByArchiveNbr(recordVO.archiveNbr));

// For now we only send displayTimeInEDTF. This will evolve until we can
// update the whole record using this method.
const stelaRecord = await firstValueFrom(
this.httpV2.patch<StelaRecord>(`v2/records/${recordId}`, {
displayTimeInEDTF: recordVO.displayTimeInEDTF,
}),
);

const simulatedV1RecordResponseResults = stelaRecord.map((record) => ({
data: [
{
RecordVO: convertStelaRecordToRecordVO(record),
},
],
message: ['Record updated'],
status: true,
resultDT: new Date().toISOString(),
createdDT: null,
updatedDT: null,
}));

return new RecordResponse({
isSuccessful: true,
isSystemUp: true,
Results: simulatedV1RecordResponseResults,
});
}

private getThumbnailCache(): ThumbnailCache {
const storage = new StorageService();
return new ThumbnailCache(storage);
Expand Down