pr feedback

This commit is contained in:
martabal 2023-11-13 17:01:48 +01:00
parent 0ed5dc869a
commit 5c37b27fcf
No known key found for this signature in database
GPG key ID: C00196E3148A52BD

View file

@ -3,9 +3,14 @@ import { Optional } from '@nestjs/common';
import { ApiProperty } from '@nestjs/swagger';
import { IsEnum } from 'class-validator';
export const getRandomAvatarColor = (value: number): UserAvatarColor => {
export const getRandomAvatarColor = (user: UserEntity): UserAvatarColor => {
const values = Object.values(UserAvatarColor);
const randomIndex = Math.floor(value % values.length);
const randomIndex = Math.floor(
user.email
.split('')
.map((letter) => letter.charCodeAt(0))
.reduce((a, b) => a + b, 0) % values.length,
);
return values[randomIndex] as UserAvatarColor;
};
@ -38,14 +43,7 @@ export const mapSimpleUser = (entity: UserEntity): UserDto => {
email: entity.email,
name: entity.name,
profileImagePath: entity.profileImagePath,
avatarColor:
entity.avatarColor ??
getRandomAvatarColor(
entity.email
.split('')
.map((letter) => letter.charCodeAt(0))
.reduce((a, b) => a + b, 0),
),
avatarColor: entity.avatarColor ?? getRandomAvatarColor(entity),
};
};