feat: random avatar color on user creation
This commit is contained in:
parent
8c1e782f8f
commit
4f77d06592
2 changed files with 8 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue