mirror of
https://github.com/immich-app/immich.git
synced 2026-03-25 11:08:56 +03:00
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>
This commit is contained in:
@@ -1,9 +1,38 @@
|
||||
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 UpdateStackParentDto {
|
||||
@ValidateUUID()
|
||||
oldParentId!: string;
|
||||
|
||||
@ValidateUUID()
|
||||
newParentId!: string;
|
||||
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 })),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user