2024-05-27 22:16:53 -04:00
|
|
|
import { ApiProperty } from '@nestjs/swagger';
|
|
|
|
|
import { Type } from 'class-transformer';
|
|
|
|
|
import { IsEnum, ValidateNested } from 'class-validator';
|
|
|
|
|
import { UserAvatarColor, UserPreferences } from 'src/entities/user-metadata.entity';
|
|
|
|
|
import { Optional, ValidateBoolean } from 'src/validation';
|
|
|
|
|
|
|
|
|
|
class AvatarUpdate {
|
|
|
|
|
@Optional()
|
|
|
|
|
@IsEnum(UserAvatarColor)
|
|
|
|
|
@ApiProperty({ enumName: 'UserAvatarColor', enum: UserAvatarColor })
|
|
|
|
|
color?: UserAvatarColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MemoryUpdate {
|
|
|
|
|
@ValidateBoolean({ optional: true })
|
|
|
|
|
enabled?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-03 16:00:20 -05:00
|
|
|
class EmailNotificationsUpdate {
|
|
|
|
|
@ValidateBoolean({ optional: true })
|
|
|
|
|
enabled?: boolean;
|
|
|
|
|
|
|
|
|
|
@ValidateBoolean({ optional: true })
|
|
|
|
|
albumInvite?: boolean;
|
|
|
|
|
|
|
|
|
|
@ValidateBoolean({ optional: true })
|
|
|
|
|
albumUpdate?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 22:16:53 -04:00
|
|
|
export class UserPreferencesUpdateDto {
|
|
|
|
|
@Optional()
|
|
|
|
|
@ValidateNested()
|
|
|
|
|
@Type(() => AvatarUpdate)
|
|
|
|
|
avatar?: AvatarUpdate;
|
|
|
|
|
|
|
|
|
|
@Optional()
|
|
|
|
|
@ValidateNested()
|
|
|
|
|
@Type(() => MemoryUpdate)
|
|
|
|
|
memories?: MemoryUpdate;
|
2024-06-03 16:00:20 -05:00
|
|
|
|
|
|
|
|
@Optional()
|
|
|
|
|
@ValidateNested()
|
|
|
|
|
@Type(() => EmailNotificationsUpdate)
|
|
|
|
|
emailNotifications?: EmailNotificationsUpdate;
|
2024-05-27 22:16:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AvatarResponse {
|
|
|
|
|
@ApiProperty({ enumName: 'UserAvatarColor', enum: UserAvatarColor })
|
|
|
|
|
color!: UserAvatarColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MemoryResponse {
|
|
|
|
|
enabled!: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-03 16:00:20 -05:00
|
|
|
class EmailNotificationsResponse {
|
|
|
|
|
enabled!: boolean;
|
|
|
|
|
albumInvite!: boolean;
|
|
|
|
|
albumUpdate!: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 22:16:53 -04:00
|
|
|
export class UserPreferencesResponseDto implements UserPreferences {
|
|
|
|
|
memories!: MemoryResponse;
|
|
|
|
|
avatar!: AvatarResponse;
|
2024-06-03 16:00:20 -05:00
|
|
|
emailNotifications!: EmailNotificationsResponse;
|
2024-05-27 22:16:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const mapPreferences = (preferences: UserPreferences): UserPreferencesResponseDto => {
|
|
|
|
|
return preferences;
|
|
|
|
|
};
|