21 lines
657 B
TypeScript
21 lines
657 B
TypeScript
|
|
import { Name } from "@repo/rdx-ddd";
|
||
|
|
import { Result } from "@repo/rdx-utils";
|
||
|
|
|
||
|
|
import {
|
||
|
|
BrandError,
|
||
|
|
type BrandInput,
|
||
|
|
BrandInputSchema,
|
||
|
|
type BrandProps,
|
||
|
|
} from "../domain/brand.aggregate";
|
||
|
|
export function mapBrandInput(input: BrandInput, builtin = false): Result<BrandProps, BrandError> {
|
||
|
|
const parsed = BrandInputSchema.safeParse(input);
|
||
|
|
if (!parsed.success) {
|
||
|
|
return Result.fail(new BrandError("INVALID_REQUEST"));
|
||
|
|
}
|
||
|
|
const name = Name.create(parsed.data.name, 100);
|
||
|
|
if (!name.isSuccess) {
|
||
|
|
return Result.fail(new BrandError("INVALID_REQUEST"));
|
||
|
|
}
|
||
|
|
return Result.ok({ name: name.data, active: parsed.data.active, builtin });
|
||
|
|
}
|