mirror of
https://github.com/immich-app/immich.git
synced 2025-12-26 09:14:58 +03:00
refactor(server): move filters to getByDayOfYear query (#14628)
move filters to getByDayOfYear query
This commit is contained in:
@@ -80,7 +80,20 @@ describe(AssetService.name, () => {
|
||||
const image4 = { ...assetStub.image, localDateTime: new Date(2009, 1, 15) };
|
||||
|
||||
partnerMock.getAll.mockResolvedValue([]);
|
||||
assetMock.getByDayOfYear.mockResolvedValue([image1, image2, image3, image4]);
|
||||
assetMock.getByDayOfYear.mockResolvedValue([
|
||||
{
|
||||
yearsAgo: 1,
|
||||
assets: [image1, image2],
|
||||
},
|
||||
{
|
||||
yearsAgo: 9,
|
||||
assets: [image3],
|
||||
},
|
||||
{
|
||||
yearsAgo: 15,
|
||||
assets: [image4],
|
||||
},
|
||||
]);
|
||||
|
||||
await expect(sut.getMemoryLane(authStub.admin, { day: 15, month: 1 })).resolves.toEqual([
|
||||
{ yearsAgo: 1, title: '1 year ago', assets: [mapAsset(image1), mapAsset(image2)] },
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user