Skip to content

Commit

Permalink
Add creation date info to missingInStorage case (#7523)
Browse files Browse the repository at this point in the history
  • Loading branch information
daneryl authored Dec 4, 2024
1 parent 7540e85 commit be44e62
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
12 changes: 10 additions & 2 deletions app/api/files.v2/FilesHealthCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export class FilesHealthCheck {
private onMissingInDBCB: (file: missingInDBFileDTO) => void = () => {};

// eslint-disable-next-line class-methods-use-this
private onMissingInStorageCB: (fileDTO: { _id: string; filename: string }) => void = () => {};
private onMissingInStorageCB: (fileDTO: {
_id: string;
filename: string;
creationDate?: Date;
}) => void = () => {};

private fileStorage: FileStorage;

Expand Down Expand Up @@ -59,7 +63,11 @@ export class FilesHealthCheck {
if (!existsInStorage && !(file instanceof URLAttachment)) {
counters.missingInStorage += 1;
missingInStorageList.push(this.fileStorage.getPath(file));
this.onMissingInStorageCB({ _id: file.id, filename: file.filename });
this.onMissingInStorageCB({
_id: file.id,
filename: file.filename,
creationDate: file.creationDate,
});
}
});

Expand Down
8 changes: 4 additions & 4 deletions app/api/files.v2/database/FilesMappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export const FileMappers = {
fileDBO.entity,
fileDBO.totalPages,
fileDBO.url
);
).withCreationDate(new Date(fileDBO.creationDate));
}
if (fileDBO.type === 'attachment') {
return new Attachment(
fileDBO._id.toString(),
fileDBO.entity,
fileDBO.totalPages,
fileDBO.filename
);
).withCreationDate(new Date(fileDBO.creationDate));
}

if (fileDBO.type === 'custom') {
Expand All @@ -41,13 +41,13 @@ export const FileMappers = {
fileDBO.entity,
fileDBO.totalPages,
fileDBO.filename
);
).withCreationDate(new Date(fileDBO.creationDate));
}
return new Document(
fileDBO._id.toString(),
fileDBO.entity,
fileDBO.totalPages,
fileDBO.filename
);
).withCreationDate(new Date(fileDBO.creationDate));
},
};
1 change: 1 addition & 0 deletions app/api/files.v2/database/schemas/filesTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface BaseFileDBOType {
entity: string;
filename: string;
url: string;
creationDate: number;
}

interface DocumentFileDBOType extends BaseFileDBOType {
Expand Down
7 changes: 7 additions & 0 deletions app/api/files.v2/model/BaseFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ export class BaseFile {

readonly totalPages: number;

creationDate?: Date;

constructor(id: string, entity: string, totalPages: number) {
this.id = id;
this.entity = entity;
this.totalPages = totalPages;
}

withCreationDate(date: Date) {
this.creationDate = date;
return this;
}
}
10 changes: 7 additions & 3 deletions app/api/files.v2/specs/FilesHealthCheck.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,12 @@ describe('FilesHealthCheck', () => {

it('should be able to subscribe to an "event" for each file missing in storage', async () => {
testStorageFiles = [];
const creationDate = Date.now();
await testingEnvironment.setUp({
files: [factory.document('file1'), factory.document('file2')],
files: [
factory.document('file1', { creationDate }),
factory.document('file2', { creationDate }),
],
});

const events: { _id: string; filename: string }[] = [];
Expand All @@ -240,8 +244,8 @@ describe('FilesHealthCheck', () => {
await filesHealthCheck.execute();

expect(events).toEqual([
{ _id: factory.idString('file1'), filename: 'file1' },
{ _id: factory.idString('file2'), filename: 'file2' },
{ _id: factory.idString('file1'), filename: 'file1', creationDate: new Date(creationDate) },
{ _id: factory.idString('file2'), filename: 'file2', creationDate: new Date(creationDate) },
]);
});
});

0 comments on commit be44e62

Please sign in to comment.