feat: random avatar color on user creation

This commit is contained in:
martabal 2023-11-01 19:06:35 +01:00
parent 8c1e782f8f
commit 4f77d06592
No known key found for this signature in database
GPG key ID: C00196E3148A52BD
2 changed files with 8 additions and 1 deletions

View file

@ -13,6 +13,12 @@ export enum UserAvatarColor {
AMBER = 'amber',
}
export const getRandomAvatarColor = (): UserAvatarColor => {
const values = Object.values(UserAvatarColor);
const randomIndex = Math.floor(Math.random() * values.length);
return values[randomIndex] as UserAvatarColor;
}
export class UserDto {
id!: string;
firstName!: string;

View file

@ -4,6 +4,7 @@ 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;
@ -104,7 +105,7 @@ 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,