2024-08-19 13:37:15 -04:00
|
|
|
import { ArrayMinSize } from 'class-validator';
|
2025-04-12 14:33:35 +02:00
|
|
|
import { Stack } from 'src/database';
|
2024-08-19 13:37:15 -04:00
|
|
|
import { AssetResponseDto, mapAsset } from 'src/dtos/asset-response.dto';
|
|
|
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
2024-03-20 15:04:03 -05:00
|
|
|
import { ValidateUUID } from 'src/validation';
|
2023-10-22 02:38:07 +00:00
|
|
|
|
2024-08-19 13:37:15 -04:00
|
|
|
export class StackCreateDto {
|
|
|
|
|
/** first asset becomes the primary */
|
|
|
|
|
@ValidateUUID({ each: true })
|
|
|
|
|
@ArrayMinSize(2)
|
|
|
|
|
assetIds!: string[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class StackSearchDto {
|
2025-03-18 19:54:50 +03:00
|
|
|
@ValidateUUID({ optional: true })
|
2024-08-19 13:37:15 -04:00
|
|
|
primaryAssetId?: string;
|
|
|
|
|
}
|
2023-10-22 02:38:07 +00:00
|
|
|
|
2024-08-19 13:37:15 -04:00
|
|
|
export class StackUpdateDto {
|
|
|
|
|
@ValidateUUID({ optional: true })
|
|
|
|
|
primaryAssetId?: string;
|
2023-10-22 02:38:07 +00:00
|
|
|
}
|
2024-08-19 13:37:15 -04:00
|
|
|
|
|
|
|
|
export class StackResponseDto {
|
|
|
|
|
id!: string;
|
|
|
|
|
primaryAssetId!: string;
|
|
|
|
|
assets!: AssetResponseDto[];
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-12 14:33:35 +02:00
|
|
|
export const mapStack = (stack: Stack, { auth }: { auth?: AuthDto }) => {
|
2024-08-19 13:37:15 -04:00
|
|
|
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 })),
|
|
|
|
|
};
|
|
|
|
|
};
|