metis-desk/modules/assets/src/api/application/brand-input.mapper.ts
2026-10-08 16:43:34 +02:00

17 lines
687 B
TypeScript

import { Name } from "@repo/rdx-ddd";
import { Result } from "@repo/rdx-utils";
import type { BrandInput, BrandProps } from "../domain/brand.aggregate";
import { BrandError, BrandInputSchema } 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 });
}