diff --git a/cli/src/api/open-api/api.ts b/cli/src/api/open-api/api.ts index 999090bb9..4eb5e1228 100644 --- a/cli/src/api/open-api/api.ts +++ b/cli/src/api/open-api/api.ts @@ -2357,10 +2357,10 @@ export interface OAuthConfigResponseDto { export interface PartnerResponseDto { /** * - * @type {string} + * @type {UserAvatarColor} * @memberof PartnerResponseDto */ - 'avatarColor': PartnerResponseDtoAvatarColorEnum; + 'avatarColor': UserAvatarColor; /** * * @type {string} @@ -2447,20 +2447,6 @@ export interface PartnerResponseDto { 'updatedAt': string; } -export const PartnerResponseDtoAvatarColorEnum = { - Primary: 'primary', - Pink: 'pink', - Red: 'red', - Yellow: 'yellow', - Blue: 'blue', - Green: 'green', - Purple: 'purple', - Orange: 'orange', - Gray: 'gray', - Amber: 'amber' -} as const; - -export type PartnerResponseDtoAvatarColorEnum = typeof PartnerResponseDtoAvatarColorEnum[keyof typeof PartnerResponseDtoAvatarColorEnum]; /** * @@ -4496,10 +4482,10 @@ export type UserAvatarColor = typeof UserAvatarColor[keyof typeof UserAvatarColo export interface UserDto { /** * - * @type {string} + * @type {UserAvatarColor} * @memberof UserDto */ - 'avatarColor': UserDtoAvatarColorEnum; + 'avatarColor': UserAvatarColor; /** * * @type {string} @@ -4526,20 +4512,6 @@ export interface UserDto { 'profileImagePath': string; } -export const UserDtoAvatarColorEnum = { - Primary: 'primary', - Pink: 'pink', - Red: 'red', - Yellow: 'yellow', - Blue: 'blue', - Green: 'green', - Purple: 'purple', - Orange: 'orange', - Gray: 'gray', - Amber: 'amber' -} as const; - -export type UserDtoAvatarColorEnum = typeof UserDtoAvatarColorEnum[keyof typeof UserDtoAvatarColorEnum]; /** * @@ -4549,10 +4521,10 @@ export type UserDtoAvatarColorEnum = typeof UserDtoAvatarColorEnum[keyof typeof export interface UserResponseDto { /** * - * @type {string} + * @type {UserAvatarColor} * @memberof UserResponseDto */ - 'avatarColor': UserResponseDtoAvatarColorEnum; + 'avatarColor': UserAvatarColor; /** * * @type {string} @@ -4633,20 +4605,6 @@ export interface UserResponseDto { 'updatedAt': string; } -export const UserResponseDtoAvatarColorEnum = { - Primary: 'primary', - Pink: 'pink', - Red: 'red', - Yellow: 'yellow', - Blue: 'blue', - Green: 'green', - Purple: 'purple', - Orange: 'orange', - Gray: 'gray', - Amber: 'amber' -} as const; - -export type UserResponseDtoAvatarColorEnum = typeof UserResponseDtoAvatarColorEnum[keyof typeof UserResponseDtoAvatarColorEnum]; /** * diff --git a/mobile/openapi/doc/PartnerResponseDto.md b/mobile/openapi/doc/PartnerResponseDto.md index ea9349a67..574b96f8d 100644 --- a/mobile/openapi/doc/PartnerResponseDto.md +++ b/mobile/openapi/doc/PartnerResponseDto.md @@ -8,7 +8,7 @@ import 'package:openapi/api.dart'; ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**avatarColor** | **String** | | +**avatarColor** | [**UserAvatarColor**](UserAvatarColor.md) | | **createdAt** | [**DateTime**](DateTime.md) | | **deletedAt** | [**DateTime**](DateTime.md) | | **email** | **String** | | diff --git a/mobile/openapi/doc/UserDto.md b/mobile/openapi/doc/UserDto.md index d83fe9640..7e5770f84 100644 --- a/mobile/openapi/doc/UserDto.md +++ b/mobile/openapi/doc/UserDto.md @@ -8,7 +8,7 @@ import 'package:openapi/api.dart'; ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**avatarColor** | **String** | | +**avatarColor** | [**UserAvatarColor**](UserAvatarColor.md) | | **email** | **String** | | **id** | **String** | | **name** | **String** | | diff --git a/mobile/openapi/doc/UserResponseDto.md b/mobile/openapi/doc/UserResponseDto.md index c22aaade6..93f9aa62a 100644 --- a/mobile/openapi/doc/UserResponseDto.md +++ b/mobile/openapi/doc/UserResponseDto.md @@ -8,7 +8,7 @@ import 'package:openapi/api.dart'; ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**avatarColor** | **String** | | +**avatarColor** | [**UserAvatarColor**](UserAvatarColor.md) | | **createdAt** | [**DateTime**](DateTime.md) | | **deletedAt** | [**DateTime**](DateTime.md) | | **email** | **String** | | diff --git a/mobile/openapi/lib/model/partner_response_dto.dart b/mobile/openapi/lib/model/partner_response_dto.dart index bb2279010..6e1776b26 100644 --- a/mobile/openapi/lib/model/partner_response_dto.dart +++ b/mobile/openapi/lib/model/partner_response_dto.dart @@ -30,7 +30,7 @@ class PartnerResponseDto { required this.updatedAt, }); - PartnerResponseDtoAvatarColorEnum avatarColor; + UserAvatarColor avatarColor; DateTime createdAt; @@ -160,7 +160,7 @@ class PartnerResponseDto { final json = value.cast(); return PartnerResponseDto( - avatarColor: PartnerResponseDtoAvatarColorEnum.fromJson(json[r'avatarColor'])!, + avatarColor: UserAvatarColor.fromJson(json[r'avatarColor'])!, createdAt: mapDateTime(json, r'createdAt', '')!, deletedAt: mapDateTime(json, r'deletedAt', ''), email: mapValueOfType(json, r'email')!, @@ -238,101 +238,3 @@ class PartnerResponseDto { }; } - -class PartnerResponseDtoAvatarColorEnum { - /// Instantiate a new enum with the provided [value]. - const PartnerResponseDtoAvatarColorEnum._(this.value); - - /// The underlying value of this enum member. - final String value; - - @override - String toString() => value; - - String toJson() => value; - - static const primary = PartnerResponseDtoAvatarColorEnum._(r'primary'); - static const pink = PartnerResponseDtoAvatarColorEnum._(r'pink'); - static const red = PartnerResponseDtoAvatarColorEnum._(r'red'); - static const yellow = PartnerResponseDtoAvatarColorEnum._(r'yellow'); - static const blue = PartnerResponseDtoAvatarColorEnum._(r'blue'); - static const green = PartnerResponseDtoAvatarColorEnum._(r'green'); - static const purple = PartnerResponseDtoAvatarColorEnum._(r'purple'); - static const orange = PartnerResponseDtoAvatarColorEnum._(r'orange'); - static const gray = PartnerResponseDtoAvatarColorEnum._(r'gray'); - static const amber = PartnerResponseDtoAvatarColorEnum._(r'amber'); - - /// List of all possible values in this [enum][PartnerResponseDtoAvatarColorEnum]. - static const values = [ - primary, - pink, - red, - yellow, - blue, - green, - purple, - orange, - gray, - amber, - ]; - - static PartnerResponseDtoAvatarColorEnum? fromJson(dynamic value) => PartnerResponseDtoAvatarColorEnumTypeTransformer().decode(value); - - static List? listFromJson(dynamic json, {bool growable = false,}) { - final result = []; - if (json is List && json.isNotEmpty) { - for (final row in json) { - final value = PartnerResponseDtoAvatarColorEnum.fromJson(row); - if (value != null) { - result.add(value); - } - } - } - return result.toList(growable: growable); - } -} - -/// Transformation class that can [encode] an instance of [PartnerResponseDtoAvatarColorEnum] to String, -/// and [decode] dynamic data back to [PartnerResponseDtoAvatarColorEnum]. -class PartnerResponseDtoAvatarColorEnumTypeTransformer { - factory PartnerResponseDtoAvatarColorEnumTypeTransformer() => _instance ??= const PartnerResponseDtoAvatarColorEnumTypeTransformer._(); - - const PartnerResponseDtoAvatarColorEnumTypeTransformer._(); - - String encode(PartnerResponseDtoAvatarColorEnum data) => data.value; - - /// Decodes a [dynamic value][data] to a PartnerResponseDtoAvatarColorEnum. - /// - /// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully, - /// then null is returned. However, if [allowNull] is false and the [dynamic value][data] - /// cannot be decoded successfully, then an [UnimplementedError] is thrown. - /// - /// The [allowNull] is very handy when an API changes and a new enum value is added or removed, - /// and users are still using an old app with the old code. - PartnerResponseDtoAvatarColorEnum? decode(dynamic data, {bool allowNull = true}) { - if (data != null) { - switch (data) { - case r'primary': return PartnerResponseDtoAvatarColorEnum.primary; - case r'pink': return PartnerResponseDtoAvatarColorEnum.pink; - case r'red': return PartnerResponseDtoAvatarColorEnum.red; - case r'yellow': return PartnerResponseDtoAvatarColorEnum.yellow; - case r'blue': return PartnerResponseDtoAvatarColorEnum.blue; - case r'green': return PartnerResponseDtoAvatarColorEnum.green; - case r'purple': return PartnerResponseDtoAvatarColorEnum.purple; - case r'orange': return PartnerResponseDtoAvatarColorEnum.orange; - case r'gray': return PartnerResponseDtoAvatarColorEnum.gray; - case r'amber': return PartnerResponseDtoAvatarColorEnum.amber; - default: - if (!allowNull) { - throw ArgumentError('Unknown enum value to decode: $data'); - } - } - } - return null; - } - - /// Singleton [PartnerResponseDtoAvatarColorEnumTypeTransformer] instance. - static PartnerResponseDtoAvatarColorEnumTypeTransformer? _instance; -} - - diff --git a/mobile/openapi/lib/model/user_dto.dart b/mobile/openapi/lib/model/user_dto.dart index d0ab8bae6..ad39f84e0 100644 --- a/mobile/openapi/lib/model/user_dto.dart +++ b/mobile/openapi/lib/model/user_dto.dart @@ -20,7 +20,7 @@ class UserDto { required this.profileImagePath, }); - UserDtoAvatarColorEnum avatarColor; + UserAvatarColor avatarColor; String email; @@ -68,7 +68,7 @@ class UserDto { final json = value.cast(); return UserDto( - avatarColor: UserDtoAvatarColorEnum.fromJson(json[r'avatarColor'])!, + avatarColor: UserAvatarColor.fromJson(json[r'avatarColor'])!, email: mapValueOfType(json, r'email')!, id: mapValueOfType(json, r'id')!, name: mapValueOfType(json, r'name')!, @@ -128,101 +128,3 @@ class UserDto { }; } - -class UserDtoAvatarColorEnum { - /// Instantiate a new enum with the provided [value]. - const UserDtoAvatarColorEnum._(this.value); - - /// The underlying value of this enum member. - final String value; - - @override - String toString() => value; - - String toJson() => value; - - static const primary = UserDtoAvatarColorEnum._(r'primary'); - static const pink = UserDtoAvatarColorEnum._(r'pink'); - static const red = UserDtoAvatarColorEnum._(r'red'); - static const yellow = UserDtoAvatarColorEnum._(r'yellow'); - static const blue = UserDtoAvatarColorEnum._(r'blue'); - static const green = UserDtoAvatarColorEnum._(r'green'); - static const purple = UserDtoAvatarColorEnum._(r'purple'); - static const orange = UserDtoAvatarColorEnum._(r'orange'); - static const gray = UserDtoAvatarColorEnum._(r'gray'); - static const amber = UserDtoAvatarColorEnum._(r'amber'); - - /// List of all possible values in this [enum][UserDtoAvatarColorEnum]. - static const values = [ - primary, - pink, - red, - yellow, - blue, - green, - purple, - orange, - gray, - amber, - ]; - - static UserDtoAvatarColorEnum? fromJson(dynamic value) => UserDtoAvatarColorEnumTypeTransformer().decode(value); - - static List? listFromJson(dynamic json, {bool growable = false,}) { - final result = []; - if (json is List && json.isNotEmpty) { - for (final row in json) { - final value = UserDtoAvatarColorEnum.fromJson(row); - if (value != null) { - result.add(value); - } - } - } - return result.toList(growable: growable); - } -} - -/// Transformation class that can [encode] an instance of [UserDtoAvatarColorEnum] to String, -/// and [decode] dynamic data back to [UserDtoAvatarColorEnum]. -class UserDtoAvatarColorEnumTypeTransformer { - factory UserDtoAvatarColorEnumTypeTransformer() => _instance ??= const UserDtoAvatarColorEnumTypeTransformer._(); - - const UserDtoAvatarColorEnumTypeTransformer._(); - - String encode(UserDtoAvatarColorEnum data) => data.value; - - /// Decodes a [dynamic value][data] to a UserDtoAvatarColorEnum. - /// - /// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully, - /// then null is returned. However, if [allowNull] is false and the [dynamic value][data] - /// cannot be decoded successfully, then an [UnimplementedError] is thrown. - /// - /// The [allowNull] is very handy when an API changes and a new enum value is added or removed, - /// and users are still using an old app with the old code. - UserDtoAvatarColorEnum? decode(dynamic data, {bool allowNull = true}) { - if (data != null) { - switch (data) { - case r'primary': return UserDtoAvatarColorEnum.primary; - case r'pink': return UserDtoAvatarColorEnum.pink; - case r'red': return UserDtoAvatarColorEnum.red; - case r'yellow': return UserDtoAvatarColorEnum.yellow; - case r'blue': return UserDtoAvatarColorEnum.blue; - case r'green': return UserDtoAvatarColorEnum.green; - case r'purple': return UserDtoAvatarColorEnum.purple; - case r'orange': return UserDtoAvatarColorEnum.orange; - case r'gray': return UserDtoAvatarColorEnum.gray; - case r'amber': return UserDtoAvatarColorEnum.amber; - default: - if (!allowNull) { - throw ArgumentError('Unknown enum value to decode: $data'); - } - } - } - return null; - } - - /// Singleton [UserDtoAvatarColorEnumTypeTransformer] instance. - static UserDtoAvatarColorEnumTypeTransformer? _instance; -} - - diff --git a/mobile/openapi/lib/model/user_response_dto.dart b/mobile/openapi/lib/model/user_response_dto.dart index 5674f08bf..11a182b6b 100644 --- a/mobile/openapi/lib/model/user_response_dto.dart +++ b/mobile/openapi/lib/model/user_response_dto.dart @@ -29,7 +29,7 @@ class UserResponseDto { required this.updatedAt, }); - UserResponseDtoAvatarColorEnum avatarColor; + UserAvatarColor avatarColor; DateTime createdAt; @@ -144,7 +144,7 @@ class UserResponseDto { final json = value.cast(); return UserResponseDto( - avatarColor: UserResponseDtoAvatarColorEnum.fromJson(json[r'avatarColor'])!, + avatarColor: UserAvatarColor.fromJson(json[r'avatarColor'])!, createdAt: mapDateTime(json, r'createdAt', '')!, deletedAt: mapDateTime(json, r'deletedAt', ''), email: mapValueOfType(json, r'email')!, @@ -221,101 +221,3 @@ class UserResponseDto { }; } - -class UserResponseDtoAvatarColorEnum { - /// Instantiate a new enum with the provided [value]. - const UserResponseDtoAvatarColorEnum._(this.value); - - /// The underlying value of this enum member. - final String value; - - @override - String toString() => value; - - String toJson() => value; - - static const primary = UserResponseDtoAvatarColorEnum._(r'primary'); - static const pink = UserResponseDtoAvatarColorEnum._(r'pink'); - static const red = UserResponseDtoAvatarColorEnum._(r'red'); - static const yellow = UserResponseDtoAvatarColorEnum._(r'yellow'); - static const blue = UserResponseDtoAvatarColorEnum._(r'blue'); - static const green = UserResponseDtoAvatarColorEnum._(r'green'); - static const purple = UserResponseDtoAvatarColorEnum._(r'purple'); - static const orange = UserResponseDtoAvatarColorEnum._(r'orange'); - static const gray = UserResponseDtoAvatarColorEnum._(r'gray'); - static const amber = UserResponseDtoAvatarColorEnum._(r'amber'); - - /// List of all possible values in this [enum][UserResponseDtoAvatarColorEnum]. - static const values = [ - primary, - pink, - red, - yellow, - blue, - green, - purple, - orange, - gray, - amber, - ]; - - static UserResponseDtoAvatarColorEnum? fromJson(dynamic value) => UserResponseDtoAvatarColorEnumTypeTransformer().decode(value); - - static List? listFromJson(dynamic json, {bool growable = false,}) { - final result = []; - if (json is List && json.isNotEmpty) { - for (final row in json) { - final value = UserResponseDtoAvatarColorEnum.fromJson(row); - if (value != null) { - result.add(value); - } - } - } - return result.toList(growable: growable); - } -} - -/// Transformation class that can [encode] an instance of [UserResponseDtoAvatarColorEnum] to String, -/// and [decode] dynamic data back to [UserResponseDtoAvatarColorEnum]. -class UserResponseDtoAvatarColorEnumTypeTransformer { - factory UserResponseDtoAvatarColorEnumTypeTransformer() => _instance ??= const UserResponseDtoAvatarColorEnumTypeTransformer._(); - - const UserResponseDtoAvatarColorEnumTypeTransformer._(); - - String encode(UserResponseDtoAvatarColorEnum data) => data.value; - - /// Decodes a [dynamic value][data] to a UserResponseDtoAvatarColorEnum. - /// - /// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully, - /// then null is returned. However, if [allowNull] is false and the [dynamic value][data] - /// cannot be decoded successfully, then an [UnimplementedError] is thrown. - /// - /// The [allowNull] is very handy when an API changes and a new enum value is added or removed, - /// and users are still using an old app with the old code. - UserResponseDtoAvatarColorEnum? decode(dynamic data, {bool allowNull = true}) { - if (data != null) { - switch (data) { - case r'primary': return UserResponseDtoAvatarColorEnum.primary; - case r'pink': return UserResponseDtoAvatarColorEnum.pink; - case r'red': return UserResponseDtoAvatarColorEnum.red; - case r'yellow': return UserResponseDtoAvatarColorEnum.yellow; - case r'blue': return UserResponseDtoAvatarColorEnum.blue; - case r'green': return UserResponseDtoAvatarColorEnum.green; - case r'purple': return UserResponseDtoAvatarColorEnum.purple; - case r'orange': return UserResponseDtoAvatarColorEnum.orange; - case r'gray': return UserResponseDtoAvatarColorEnum.gray; - case r'amber': return UserResponseDtoAvatarColorEnum.amber; - default: - if (!allowNull) { - throw ArgumentError('Unknown enum value to decode: $data'); - } - } - } - return null; - } - - /// Singleton [UserResponseDtoAvatarColorEnumTypeTransformer] instance. - static UserResponseDtoAvatarColorEnumTypeTransformer? _instance; -} - - diff --git a/mobile/openapi/test/partner_response_dto_test.dart b/mobile/openapi/test/partner_response_dto_test.dart index c74604a35..50ac1d805 100644 --- a/mobile/openapi/test/partner_response_dto_test.dart +++ b/mobile/openapi/test/partner_response_dto_test.dart @@ -16,7 +16,7 @@ void main() { // final instance = PartnerResponseDto(); group('test PartnerResponseDto', () { - // String avatarColor + // UserAvatarColor avatarColor test('to test the property `avatarColor`', () async { // TODO }); diff --git a/mobile/openapi/test/user_dto_test.dart b/mobile/openapi/test/user_dto_test.dart index d9cf96cf0..20229ff65 100644 --- a/mobile/openapi/test/user_dto_test.dart +++ b/mobile/openapi/test/user_dto_test.dart @@ -16,7 +16,7 @@ void main() { // final instance = UserDto(); group('test UserDto', () { - // String avatarColor + // UserAvatarColor avatarColor test('to test the property `avatarColor`', () async { // TODO }); diff --git a/mobile/openapi/test/user_response_dto_test.dart b/mobile/openapi/test/user_response_dto_test.dart index dd1cf0927..aa0717e74 100644 --- a/mobile/openapi/test/user_response_dto_test.dart +++ b/mobile/openapi/test/user_response_dto_test.dart @@ -16,7 +16,7 @@ void main() { // final instance = UserResponseDto(); group('test UserResponseDto', () { - // String avatarColor + // UserAvatarColor avatarColor test('to test the property `avatarColor`', () async { // TODO }); diff --git a/server/immich-openapi-specs.json b/server/immich-openapi-specs.json index acb6ef37d..a5fb2bbc1 100644 --- a/server/immich-openapi-specs.json +++ b/server/immich-openapi-specs.json @@ -7656,19 +7656,8 @@ "PartnerResponseDto": { "properties": { "avatarColor": { - "enum": [ - "primary", - "pink", - "red", - "yellow", - "blue", - "green", - "purple", - "orange", - "gray", - "amber" - ], - "type": "string" + "$ref": "#/components/schemas/UserAvatarColor", + "nullable": true }, "createdAt": { "format": "date-time", @@ -7720,11 +7709,11 @@ } }, "required": [ + "avatarColor", "id", "name", "email", "profileImagePath", - "avatarColor", "storageLabel", "externalPath", "shouldChangePassword", @@ -9262,19 +9251,8 @@ "UserDto": { "properties": { "avatarColor": { - "enum": [ - "primary", - "pink", - "red", - "yellow", - "blue", - "green", - "purple", - "orange", - "gray", - "amber" - ], - "type": "string" + "$ref": "#/components/schemas/UserAvatarColor", + "nullable": true }, "email": { "type": "string" @@ -9290,30 +9268,19 @@ } }, "required": [ + "avatarColor", "id", "name", "email", - "profileImagePath", - "avatarColor" + "profileImagePath" ], "type": "object" }, "UserResponseDto": { "properties": { "avatarColor": { - "enum": [ - "primary", - "pink", - "red", - "yellow", - "blue", - "green", - "purple", - "orange", - "gray", - "amber" - ], - "type": "string" + "$ref": "#/components/schemas/UserAvatarColor", + "nullable": true }, "createdAt": { "format": "date-time", @@ -9362,11 +9329,11 @@ } }, "required": [ + "avatarColor", "id", "name", "email", "profileImagePath", - "avatarColor", "storageLabel", "externalPath", "shouldChangePassword", diff --git a/server/src/domain/user/response-dto/user-response.dto.ts b/server/src/domain/user/response-dto/user-response.dto.ts index 82dd86d64..b84fd8bf2 100644 --- a/server/src/domain/user/response-dto/user-response.dto.ts +++ b/server/src/domain/user/response-dto/user-response.dto.ts @@ -1,8 +1,11 @@ import { UserAvatarColor, UserEntity } from '@app/infra/entities'; +import { Optional } from '@nestjs/common'; +import { ApiProperty } from '@nestjs/swagger'; +import { IsEnum } from 'class-validator'; -export const getRandomAvatarColor = (): UserAvatarColor => { +export const getRandomAvatarColor = (value: number): UserAvatarColor => { const values = Object.values(UserAvatarColor); - const randomIndex = Math.floor(Math.random() * values.length); + const randomIndex = Math.floor(value % values.length); return values[randomIndex] as UserAvatarColor; }; @@ -11,7 +14,10 @@ export class UserDto { name!: string; email!: string; profileImagePath!: string; - avatarColor!: UserAvatarColor; + @IsEnum(UserAvatarColor) + @Optional() + @ApiProperty({ enumName: 'UserAvatarColor', enum: UserAvatarColor }) + avatarColor!: UserAvatarColor | null; } export class UserResponseDto extends UserDto { @@ -32,7 +38,7 @@ export const mapSimpleUser = (entity: UserEntity): UserDto => { email: entity.email, name: entity.name, profileImagePath: entity.profileImagePath, - avatarColor: entity.avatarColor, + avatarColor: entity.avatarColor ?? getRandomAvatarColor(entity.email.length), }; }; diff --git a/server/src/domain/user/user.core.ts b/server/src/domain/user/user.core.ts index 7822dcc14..c8e77a500 100644 --- a/server/src/domain/user/user.core.ts +++ b/server/src/domain/user/user.core.ts @@ -4,7 +4,6 @@ import path from 'path'; import sanitize from 'sanitize-filename'; import { AuthUserDto } from '../auth'; import { ICryptoRepository, ILibraryRepository, IUserRepository } from '../repositories'; -import { getRandomAvatarColor } from './response-dto/user-response.dto'; const SALT_ROUNDS = 10; @@ -99,7 +98,6 @@ export class UserCore { if (payload.storageLabel) { payload.storageLabel = sanitize(payload.storageLabel); } - payload.avatarColor = getRandomAvatarColor(); const userEntity = await this.userRepository.create(payload); await this.libraryRepository.create({ owner: { id: userEntity.id } as UserEntity, diff --git a/server/src/infra/entities/user.entity.ts b/server/src/infra/entities/user.entity.ts index 109c55f72..66ff3728f 100644 --- a/server/src/infra/entities/user.entity.ts +++ b/server/src/infra/entities/user.entity.ts @@ -31,8 +31,8 @@ export class UserEntity { @Column({ default: '' }) name!: string; - @Column({ type: 'varchar', default: UserAvatarColor.PRIMARY }) - avatarColor!: UserAvatarColor; + @Column({ type: 'varchar', default: null }) + avatarColor!: UserAvatarColor | null; @Column({ default: false }) isAdmin!: boolean; diff --git a/server/src/infra/migrations/1698847820950-AddAvatarColor.ts b/server/src/infra/migrations/1699889987493-AddAvatarColor.ts similarity index 69% rename from server/src/infra/migrations/1698847820950-AddAvatarColor.ts rename to server/src/infra/migrations/1699889987493-AddAvatarColor.ts index 3ade81f0b..b075a5d2a 100644 --- a/server/src/infra/migrations/1698847820950-AddAvatarColor.ts +++ b/server/src/infra/migrations/1699889987493-AddAvatarColor.ts @@ -1,10 +1,10 @@ import { MigrationInterface, QueryRunner } from "typeorm"; -export class AddAvatarColor1698847820950 implements MigrationInterface { - name = 'AddAvatarColor1698847820950' +export class AddAvatarColor1699889987493 implements MigrationInterface { + name = 'AddAvatarColor1699889987493' public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "users" ADD "avatarColor" character varying NOT NULL DEFAULT 'primary'`); + await queryRunner.query(`ALTER TABLE "users" ADD "avatarColor" character varying`); } public async down(queryRunner: QueryRunner): Promise { diff --git a/web/src/api/open-api/api.ts b/web/src/api/open-api/api.ts index 999090bb9..4eb5e1228 100644 --- a/web/src/api/open-api/api.ts +++ b/web/src/api/open-api/api.ts @@ -2357,10 +2357,10 @@ export interface OAuthConfigResponseDto { export interface PartnerResponseDto { /** * - * @type {string} + * @type {UserAvatarColor} * @memberof PartnerResponseDto */ - 'avatarColor': PartnerResponseDtoAvatarColorEnum; + 'avatarColor': UserAvatarColor; /** * * @type {string} @@ -2447,20 +2447,6 @@ export interface PartnerResponseDto { 'updatedAt': string; } -export const PartnerResponseDtoAvatarColorEnum = { - Primary: 'primary', - Pink: 'pink', - Red: 'red', - Yellow: 'yellow', - Blue: 'blue', - Green: 'green', - Purple: 'purple', - Orange: 'orange', - Gray: 'gray', - Amber: 'amber' -} as const; - -export type PartnerResponseDtoAvatarColorEnum = typeof PartnerResponseDtoAvatarColorEnum[keyof typeof PartnerResponseDtoAvatarColorEnum]; /** * @@ -4496,10 +4482,10 @@ export type UserAvatarColor = typeof UserAvatarColor[keyof typeof UserAvatarColo export interface UserDto { /** * - * @type {string} + * @type {UserAvatarColor} * @memberof UserDto */ - 'avatarColor': UserDtoAvatarColorEnum; + 'avatarColor': UserAvatarColor; /** * * @type {string} @@ -4526,20 +4512,6 @@ export interface UserDto { 'profileImagePath': string; } -export const UserDtoAvatarColorEnum = { - Primary: 'primary', - Pink: 'pink', - Red: 'red', - Yellow: 'yellow', - Blue: 'blue', - Green: 'green', - Purple: 'purple', - Orange: 'orange', - Gray: 'gray', - Amber: 'amber' -} as const; - -export type UserDtoAvatarColorEnum = typeof UserDtoAvatarColorEnum[keyof typeof UserDtoAvatarColorEnum]; /** * @@ -4549,10 +4521,10 @@ export type UserDtoAvatarColorEnum = typeof UserDtoAvatarColorEnum[keyof typeof export interface UserResponseDto { /** * - * @type {string} + * @type {UserAvatarColor} * @memberof UserResponseDto */ - 'avatarColor': UserResponseDtoAvatarColorEnum; + 'avatarColor': UserAvatarColor; /** * * @type {string} @@ -4633,20 +4605,6 @@ export interface UserResponseDto { 'updatedAt': string; } -export const UserResponseDtoAvatarColorEnum = { - Primary: 'primary', - Pink: 'pink', - Red: 'red', - Yellow: 'yellow', - Blue: 'blue', - Green: 'green', - Purple: 'purple', - Orange: 'orange', - Gray: 'gray', - Amber: 'amber' -} as const; - -export type UserResponseDtoAvatarColorEnum = typeof UserResponseDtoAvatarColorEnum[keyof typeof UserResponseDtoAvatarColorEnum]; /** * diff --git a/web/src/lib/components/shared-components/navigation-bar/account-info-panel.svelte b/web/src/lib/components/shared-components/navigation-bar/account-info-panel.svelte index b032ecceb..27b7423bb 100644 --- a/web/src/lib/components/shared-components/navigation-bar/account-info-panel.svelte +++ b/web/src/lib/components/shared-components/navigation-bar/account-info-panel.svelte @@ -1,7 +1,7 @@ dispatch('close')} on:escape={() => dispatch('close')}> diff --git a/web/src/lib/components/shared-components/user-avatar.svelte b/web/src/lib/components/shared-components/user-avatar.svelte index 052b8aba2..8538b0df5 100644 --- a/web/src/lib/components/shared-components/user-avatar.svelte +++ b/web/src/lib/components/shared-components/user-avatar.svelte @@ -4,18 +4,18 @@