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

17 lines
687 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";
2026-10-08 14:43:34 +00:00
import type { BrandInput, BrandProps } from "../domain/brand.aggregate";
import { BrandError, BrandInputSchema } from "../domain/brand.aggregate";
2026-10-07 16:08:48 +00:00
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 });
}