import { createContext, DomainError } from "@tailor-platform/erp-kit/app"; import { createResolver, t } from "@tailor-platform/sdk"; import { getDB } from "@/generated/kysely-tailordb"; import { bpModulesExport } from "@/modules"; export default createResolver({ name: "updateBusinessPartner", operation: "mutation", input: { id: t.string().description("id"), name: t.string({ optional: true }).description("name"), }, body: async (context) => { const ctx = createContext(context); return getDB("main-db") .transaction() .execute(async (trx) => { const result = await bpModulesExport.commands.updatePartner( trx, { id: context.input.id, name: context.input.name?.trim() }, ctx, ); if (!result.ok) { switch (result.error.code) { case "UNAUTHENTICATED": throw new DomainError("Authentication is required"); case "INSUFFICIENT_PERMISSION": throw new DomainError("You do not have permission to perform this action"); default: throw new DomainError(result.error.message); } } return { id: result.value.partnerId }; }); }, output: t.object({ id: t.string().description("ID") }), });