feat(server/web): album description (#3558)

* feat(server): add album description

* chore: open api

* fix: tests

* show and edit description on the web

* fix test

* remove unused code

* type event

* format fix

---------

Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
Jason Rasmussen
2023-08-05 22:43:26 -04:00
committed by GitHub
parent deaf81e2a4
commit 2f26a7edae
28 changed files with 287 additions and 41 deletions

View File

@@ -7,6 +7,7 @@ export class AlbumResponseDto {
id!: string;
ownerId!: string;
albumName!: string;
description!: string;
createdAt!: Date;
updatedAt!: Date;
albumThumbnailAssetId!: string | null;
@@ -19,7 +20,7 @@ export class AlbumResponseDto {
lastModifiedAssetTimestamp?: Date;
}
export function mapAlbum(entity: AlbumEntity): AlbumResponseDto {
const _map = (entity: AlbumEntity, withAssets: boolean): AlbumResponseDto => {
const sharedUsers: UserResponseDto[] = [];
entity.sharedUsers?.forEach((user) => {
@@ -29,6 +30,7 @@ export function mapAlbum(entity: AlbumEntity): AlbumResponseDto {
return {
albumName: entity.albumName,
description: entity.description,
albumThumbnailAssetId: entity.albumThumbnailAssetId,
createdAt: entity.createdAt,
updatedAt: entity.updatedAt,
@@ -37,33 +39,13 @@ export function mapAlbum(entity: AlbumEntity): AlbumResponseDto {
owner: mapUser(entity.owner),
sharedUsers,
shared: sharedUsers.length > 0 || entity.sharedLinks?.length > 0,
assets: entity.assets?.map((asset) => mapAsset(asset)) || [],
assets: withAssets ? entity.assets?.map((asset) => mapAsset(asset)) || [] : [],
assetCount: entity.assets?.length || 0,
};
}
};
export function mapAlbumExcludeAssetInfo(entity: AlbumEntity): AlbumResponseDto {
const sharedUsers: UserResponseDto[] = [];
entity.sharedUsers?.forEach((user) => {
const userDto = mapUser(user);
sharedUsers.push(userDto);
});
return {
albumName: entity.albumName,
albumThumbnailAssetId: entity.albumThumbnailAssetId,
createdAt: entity.createdAt,
updatedAt: entity.updatedAt,
id: entity.id,
ownerId: entity.ownerId,
owner: mapUser(entity.owner),
sharedUsers,
shared: sharedUsers.length > 0 || entity.sharedLinks?.length > 0,
assets: [],
assetCount: entity.assets?.length || 0,
};
}
export const mapAlbum = (entity: AlbumEntity) => _map(entity, true);
export const mapAlbumExcludeAssetInfo = (entity: AlbumEntity) => _map(entity, false);
export class AlbumCountResponseDto {
@ApiProperty({ type: 'integer' })

View File

@@ -156,6 +156,7 @@ describe(AlbumService.name, () => {
await expect(sut.create(authStub.admin, { albumName: 'Empty album' })).resolves.toEqual({
albumName: 'Empty album',
description: '',
albumThumbnailAssetId: null,
assetCount: 0,
assets: [],

View File

@@ -94,6 +94,7 @@ export class AlbumService {
const album = await this.albumRepository.create({
ownerId: authUser.id,
albumName: dto.albumName,
description: dto.description,
sharedUsers: dto.sharedWithUserIds?.map((value) => ({ id: value } as UserEntity)) ?? [],
assets: (dto.assetIds || []).map((id) => ({ id } as AssetEntity)),
albumThumbnailAssetId: dto.assetIds?.[0] || null,
@@ -118,6 +119,7 @@ export class AlbumService {
const updatedAlbum = await this.albumRepository.update({
id: album.id,
albumName: dto.albumName,
description: dto.description,
albumThumbnailAssetId: dto.albumThumbnailAssetId,
});

View File

@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString } from 'class-validator';
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { ValidateUUID } from '../../domain.util';
export class CreateAlbumDto {
@@ -8,6 +8,10 @@ export class CreateAlbumDto {
@ApiProperty()
albumName!: string;
@IsString()
@IsOptional()
description?: string;
@ValidateUUID({ optional: true, each: true })
sharedWithUserIds?: string[];

View File

@@ -1,12 +1,15 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsOptional } from 'class-validator';
import { IsOptional, IsString } from 'class-validator';
import { ValidateUUID } from '../../domain.util';
export class UpdateAlbumDto {
@IsOptional()
@ApiProperty()
@IsString()
albumName?: string;
@IsOptional()
@IsString()
description?: string;
@ValidateUUID({ optional: true })
albumThumbnailAssetId?: string;
}