Something went wrong. Try again.
A social knowledge tool for research trails, built on ATProto semble.so
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283import { ValueObject } from '../../../../../shared/domain/ValueObject';import { ok, err, Result } from '../../../../../shared/core/Result';import { CardTypeEnum } from '../CardType';import { CuratorId } from '../CuratorId';
export class NoteCardContentValidationError extends Error { constructor(message: string) { super(message); this.name = 'NoteCardContentValidationError'; }}
interface NoteCardContentProps { type: CardTypeEnum.NOTE; text: string;}
export class NoteCardContent extends ValueObject<NoteCardContentProps> { public static readonly MAX_TEXT_LENGTH = 10000;
get type(): CardTypeEnum.NOTE { return this.props.type; }
get text(): string { return this.props.text; }
private constructor(props: NoteCardContentProps) { super(props); }
public static create( text: string, ): Result<NoteCardContent, NoteCardContentValidationError> { if (!text || text.trim().length === 0) { return err( new NoteCardContentValidationError('Note text cannot be empty'), ); }
if (text.length > this.MAX_TEXT_LENGTH) { return err( new NoteCardContentValidationError( `Note text cannot exceed ${this.MAX_TEXT_LENGTH} characters`, ), ); }
return ok( new NoteCardContent({ type: CardTypeEnum.NOTE, text: text.trim(), }), ); }
public updateText( newText: string, ): Result<NoteCardContent, NoteCardContentValidationError> { if (!newText || newText.trim().length === 0) { return err( new NoteCardContentValidationError('Note text cannot be empty'), ); }
if (newText.length > NoteCardContent.MAX_TEXT_LENGTH) { return err( new NoteCardContentValidationError( `Note text cannot exceed ${NoteCardContent.MAX_TEXT_LENGTH} characters`, ), ); }
return ok( new NoteCardContent({ ...this.props, text: newText.trim(), }), ); }}