refactor: stricter repository typing

Signed-off-by: izzy <me@insrt.uk>
This commit is contained in:
izzy
2026-02-25 11:36:26 +00:00
parent 0a358090cb
commit 891a3c8123
3 changed files with 22 additions and 10 deletions
@@ -146,7 +146,12 @@ export class IntegrityRepository {
), ),
) )
.select(['allPaths.path as path', 'allPaths.assetId', 'allPaths.fileAssetId', 'integrity_report.id as reportId']) .select(['allPaths.path as path', 'allPaths.assetId', 'allPaths.fileAssetId', 'integrity_report.id as reportId'])
.stream(); .stream() as AsyncIterableIterator<
{ path: string; reportId: string | null } & (
| { assetId: string; fileAssetId: null }
| { assetId: null; fileAssetId: string }
)
>;
} }
@GenerateSql({ params: [DummyValue.DATE, DummyValue.DATE], stream: true }) @GenerateSql({ params: [DummyValue.DATE, DummyValue.DATE], stream: true })
+4 -6
View File
@@ -301,12 +301,10 @@ export interface IIntegrityUntrackedFilesJob {
} }
export interface IIntegrityMissingFilesJob { export interface IIntegrityMissingFilesJob {
items: { items: ({ path: string; reportId: string | null } & (
path: string; | { assetId: string; fileAssetId: null }
reportId: string | null; | { assetId: null; fileAssetId: string }
assetId: string | null; ))[];
fileAssetId: string | null;
}[];
} }
export interface IIntegrityPathWithReportJob { export interface IIntegrityPathWithReportJob {
@@ -468,9 +468,18 @@ describe(IntegrityService.name, () => {
const integrity = ctx.get(IntegrityRepository); const integrity = ctx.get(IntegrityRepository);
const storage = ctx.getMock(StorageRepository); const storage = ctx.getMock(StorageRepository);
const {
result: { id: ownerId },
} = await ctx.newUser();
const {
result: { id: assetId },
} = await ctx.newAsset({ ownerId, originalPath: '/path/to/file1' });
const { id: restoredId } = await integrity.create({ const { id: restoredId } = await integrity.create({
type: IntegrityReportType.MissingFile, type: IntegrityReportType.MissingFile,
path: '/path/to/restored', path: '/path/to/restored',
assetId,
}); });
storage.stat storage.stat
@@ -480,9 +489,9 @@ describe(IntegrityService.name, () => {
await sut.handleMissingFiles({ await sut.handleMissingFiles({
items: [ items: [
{ path: '/path/to/existing', assetId: null, fileAssetId: null, reportId: null }, { path: '/path/to/existing', assetId, fileAssetId: null, reportId: null },
{ path: '/path/to/missing', assetId: null, fileAssetId: null, reportId: null }, { path: '/path/to/missing', assetId, fileAssetId: null, reportId: null },
{ path: '/path/to/restored', assetId: null, fileAssetId: null, reportId: restoredId }, { path: '/path/to/restored', assetId, fileAssetId: null, reportId: restoredId },
], ],
}); });