import { ok, type CommandContext } from "@tailor-platform/erp-kit/core"; import { createActive } from "../domain/businessPartner"; import type { BusinessPartnerType } from "../generated/enums"; import type { Transaction } from "../generated/kysely-tailordb"; import { createBusinessPartnerRepository, type BusinessPartnerRepository, } from "../repository/businessPartnerRepository"; export interface CreatePartnerInput { name: string; type: BusinessPartnerType; } export async function run>( db: Transaction, input: CreatePartnerInput & CF, _ctx: CommandContext, repositoryFactory: ( db: Transaction, ) => BusinessPartnerRepository = createBusinessPartnerRepository, ) { const { name, type, ...customFields } = input; const created = createActive({ name, type, customFields }); if (!created.ok) return created; await repositoryFactory(db).save(created.value); return ok({ partnerId: created.value.id }); }