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:
Jason Rasmussen
2024-08-19 13:37:15 -04:00
committed by GitHub
parent ca52cbace1
commit 8338657eaa
63 changed files with 2321 additions and 1152 deletions

View File

@@ -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 })),
};
};