refactor(server): move filters to getByDayOfYear query (#14628)

move filters to getByDayOfYear query
This commit is contained in:
Mert 2024-12-10 16:22:47 -05:00 committed by GitHub
parent 25ca3b1124
commit 9eff1c4b34
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 55 additions and 38 deletions

View file

@ -43,28 +43,13 @@ export class AssetService extends BaseService {
});
const userIds = [auth.user.id, ...partnerIds];
const assets = await this.assetRepository.getByDayOfYear(userIds, dto);
const assetsWithThumbnails = assets.filter(({ files }) => !!getAssetFiles(files).thumbnailFile);
const groups: Record<number, AssetEntity[]> = {};
const currentYear = new Date().getFullYear();
for (const asset of assetsWithThumbnails) {
const yearsAgo = currentYear - asset.localDateTime.getFullYear();
if (!groups[yearsAgo]) {
groups[yearsAgo] = [];
}
groups[yearsAgo].push(asset);
}
return Object.keys(groups)
.map(Number)
.sort((a, b) => a - b)
.filter((yearsAgo) => yearsAgo > 0)
.map((yearsAgo) => ({
yearsAgo,
// TODO move this to clients
title: `${yearsAgo} year${yearsAgo > 1 ? 's' : ''} ago`,
assets: groups[yearsAgo].map((asset) => mapAsset(asset, { auth })),
}));
const groups = await this.assetRepository.getByDayOfYear(userIds, dto);
return groups.map(({ yearsAgo, assets }) => ({
yearsAgo,
// TODO move this to clients
title: `${yearsAgo} year${yearsAgo > 1 ? 's' : ''} ago`,
assets: assets.map((asset) => mapAsset(asset, { auth })),
}));
}
async getStatistics(auth: AuthDto, dto: AssetStatsDto) {