metis-desk/modules/assets/src/api/application/brand-input.mapper.ts

21 lines
657 B
TypeScript
Raw Normal View History

2026-10-07 16:08:48 +00:00
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 });
}