Files
2026-11-14 09:56:45 +00:00

44 lines
1.6 KiB
TypeScript

// The handlers of the module's procedures: each takes the service its kind may use and calls one use
// case. No rule lives here.
import { implement } from "@conusai-kit/core"
import { contactAdd, partyCreate, partyGet, partyList } from "../contract/index.js"
import { addContact, createParty, getParty, listParties } from "../core/crm.js"
import { crmServiceOf } from "./service.js"
export const partyListImpl = implement(partyList, ({ input, ctx }) =>
listParties(crmServiceOf(ctx.container, ctx.kind), {
...(input.q === undefined ? {} : { q: input.q }),
...(input.after === undefined ? {} : { after: input.after }),
...(input.limit === undefined ? {} : { limit: input.limit }),
}),
)
export const partyGetImpl = implement(partyGet, ({ input, ctx }) =>
getParty(crmServiceOf(ctx.container, ctx.kind), input.partyId),
)
export const partyCreateImpl = implement(partyCreate, ({ input, ctx }) =>
createParty(crmServiceOf(ctx.container, "effect"), ctx.scope, {
kind: input.kind,
displayName: input.displayName,
...(input.legalName === undefined ? {} : { legalName: input.legalName }),
country: input.country,
...(input.linkSelf === undefined ? {} : { linkSelf: input.linkSelf }),
requestId: input.requestId,
}),
)
export const contactAddImpl = implement(contactAdd, ({ input, ctx }) =>
addContact(crmServiceOf(ctx.container, "effect"), ctx.scope, {
partyId: input.partyId,
kind: input.kind,
value: input.value,
purposes: input.purposes,
isPrimary: input.isPrimary,
requestId: input.requestId,
}),
)
export const CRM_PROCEDURES = [partyListImpl, partyGetImpl, partyCreateImpl, contactAddImpl]