Files
immich/server/src/dtos/stack.dto.ts
Jason Rasmussen 8338657eaa refactor(server): stacks (#11453)
* refactor: stacks

* mobile: get it built

* chore: feedback

* fix: sync and duplicates

* mobile: remove old stack reference

* chore: add primary asset id

* revert change to asset entity

* mobile: refactor mobile api

* mobile: sync stack info after creating stack

* mobile: update timeline after deleting stack

* server: update asset updatedAt when stack is deleted

* mobile: simplify action

* mobile: rename to match dto property

* fix: web test

---------

Co-authored-by: Alex <alex.tran1502@gmail.com>
2024-08-19 12:37:15 -05:00

39 lines
1.1 KiB
TypeScript

import { ArrayMinSize } from 'class-validator';
import { AssetResponseDto, mapAsset } from 'src/dtos/asset-response.dto';
import { AuthDto } from 'src/dtos/auth.dto';
import { StackEntity } from 'src/entities/stack.entity';
import { ValidateUUID } from 'src/validation';
export class StackCreateDto {
/** first asset becomes the primary */
@ValidateUUID({ each: true })
@ArrayMinSize(2)
assetIds!: string[];
}
export class StackSearchDto {
primaryAssetId?: string;
}
export class StackUpdateDto {
@ValidateUUID({ optional: true })
primaryAssetId?: string;
}
export class StackResponseDto {
id!: string;
primaryAssetId!: string;
assets!: AssetResponseDto[];
}
export const mapStack = (stack: StackEntity, { auth }: { auth?: AuthDto }) => {
const primary = stack.assets.filter((asset) => asset.id === stack.primaryAssetId);
const others = stack.assets.filter((asset) => asset.id !== stack.primaryAssetId);
return {
id: stack.id,
primaryAssetId: stack.primaryAssetId,
assets: [...primary, ...others].map((asset) => mapAsset(asset, { auth })),
};
};