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: "updatePartnerAddress", operation: "mutation", input: { id: t.string().description("id"), line1: t.string({ optional: true }).description("line1"), city: t.string({ optional: true }).description("city"), postalCode: t.string({ optional: true }).description("postalCode"), country: t.string({ optional: true }).description("country"), line2: t.string({ optional: true }).description("line2"), state: t.string({ optional: true }).description("state"), }, body: async (context) => { const ctx = createContext(context); return getDB("main-db") .transaction() .execute(async (trx) => { const result = await bpModulesExport.commands.updatePartnerAddress( trx, { id: context.input.id, line1: context.input.line1?.trim(), city: context.input.city?.trim(), postalCode: context.input.postalCode?.trim(), country: context.input.country?.trim(), line2: context.input.line2 === undefined ? undefined : context.input.line2?.trim() || null, state: context.input.state === undefined ? undefined : context.input.state?.trim() || null, }, 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.partnerAddressId }; }); }, output: t.object({ id: t.string().description("ID") }), });