fix issues in core
This commit is contained in:
@@ -10,6 +10,7 @@ import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorC
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { Avatar } from '../../domain/entities/Avatar';
|
||||
import type { IAvatarRepository } from '../../domain/repositories/IAvatarRepository';
|
||||
import { AvatarId } from '../../domain/value-objects/AvatarId';
|
||||
|
||||
export interface UpdateAvatarInput {
|
||||
driverId: string;
|
||||
@@ -48,9 +49,9 @@ export class UpdateAvatarUseCase {
|
||||
await this.avatarRepo.save(currentAvatar);
|
||||
}
|
||||
|
||||
const avatarId = uuidv4(); // TODO this ID should be a value object
|
||||
const avatarId = AvatarId.create(uuidv4());
|
||||
const newAvatar = Avatar.create({
|
||||
id: avatarId,
|
||||
id: avatarId.toString(),
|
||||
driverId: input.driverId,
|
||||
mediaUrl: input.mediaUrl,
|
||||
});
|
||||
@@ -58,13 +59,13 @@ export class UpdateAvatarUseCase {
|
||||
await this.avatarRepo.save(newAvatar);
|
||||
|
||||
this.output.present({
|
||||
avatarId,
|
||||
avatarId: avatarId.toString(),
|
||||
driverId: input.driverId,
|
||||
});
|
||||
|
||||
this.logger.info('[UpdateAvatarUseCase] Avatar updated successfully', {
|
||||
driverId: input.driverId,
|
||||
avatarId,
|
||||
avatarId: avatarId.toString(),
|
||||
});
|
||||
|
||||
return Result.ok(undefined);
|
||||
|
||||
31
core/media/domain/value-objects/AvatarId.ts
Normal file
31
core/media/domain/value-objects/AvatarId.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { IValueObject } from '@core/shared/domain';
|
||||
|
||||
export interface AvatarIdProps {
|
||||
value: string;
|
||||
}
|
||||
|
||||
export class AvatarId implements IValueObject<AvatarIdProps> {
|
||||
public readonly props: AvatarIdProps;
|
||||
|
||||
private constructor(value: string) {
|
||||
this.props = { value };
|
||||
}
|
||||
|
||||
static create(raw: string): AvatarId {
|
||||
const value = raw?.trim();
|
||||
|
||||
if (!value) {
|
||||
throw new Error('Avatar ID cannot be empty');
|
||||
}
|
||||
|
||||
return new AvatarId(value);
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return this.props.value;
|
||||
}
|
||||
|
||||
equals(other: IValueObject<AvatarIdProps>): boolean {
|
||||
return this.props.value === other.props.value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user