86 lines
2.2 KiB
TypeScript
86 lines
2.2 KiB
TypeScript
/**
|
|
* Orders Domain - Salesforce Query Helpers
|
|
*
|
|
* Generates the field lists required to hydrate domain mappers when querying Salesforce.
|
|
*/
|
|
|
|
import type { SalesforceFieldMap } from "../../contract";
|
|
|
|
const UNIQUE = <T>(values: T[]): T[] => Array.from(new Set(values));
|
|
|
|
export function buildOrderSelectFields(
|
|
fieldMap: SalesforceFieldMap,
|
|
additional: string[] = []
|
|
): string[] {
|
|
const fields = [
|
|
"Id",
|
|
"AccountId",
|
|
"Status",
|
|
"EffectiveDate",
|
|
"OrderNumber",
|
|
"TotalAmount",
|
|
"CreatedDate",
|
|
"LastModifiedDate",
|
|
"Pricebook2Id",
|
|
fieldMap.order.orderType,
|
|
fieldMap.order.activationType,
|
|
fieldMap.order.activationScheduledAt,
|
|
fieldMap.order.activationStatus,
|
|
fieldMap.order.internetPlanTier,
|
|
fieldMap.order.installationType,
|
|
fieldMap.order.weekendInstall,
|
|
fieldMap.order.accessMode,
|
|
fieldMap.order.hikariDenwa,
|
|
fieldMap.order.vpnRegion,
|
|
fieldMap.order.simType,
|
|
fieldMap.order.simVoiceMail,
|
|
fieldMap.order.simCallWaiting,
|
|
fieldMap.order.eid,
|
|
fieldMap.order.whmcsOrderId,
|
|
fieldMap.order.addressChanged,
|
|
];
|
|
|
|
if (fieldMap.order.lastErrorCode) fields.push(fieldMap.order.lastErrorCode);
|
|
if (fieldMap.order.lastErrorMessage) fields.push(fieldMap.order.lastErrorMessage);
|
|
if (fieldMap.order.lastAttemptAt) fields.push(fieldMap.order.lastAttemptAt);
|
|
|
|
return UNIQUE([...fields, ...additional]);
|
|
}
|
|
|
|
export function buildOrderItemSelectFields(
|
|
fieldMap: SalesforceFieldMap,
|
|
additional: string[] = []
|
|
): string[] {
|
|
const fields = [
|
|
"Id",
|
|
"OrderId",
|
|
"Quantity",
|
|
"UnitPrice",
|
|
"TotalPrice",
|
|
"PricebookEntry.Id",
|
|
fieldMap.orderItem.billingCycle,
|
|
fieldMap.orderItem.whmcsServiceId,
|
|
];
|
|
|
|
return UNIQUE([...fields, ...additional]);
|
|
}
|
|
|
|
export function buildOrderItemProduct2Fields(
|
|
fieldMap: SalesforceFieldMap,
|
|
additional: string[] = []
|
|
): string[] {
|
|
const fields = [
|
|
"Id",
|
|
"Name",
|
|
fieldMap.product.sku,
|
|
fieldMap.product.whmcsProductId,
|
|
fieldMap.product.itemClass,
|
|
fieldMap.product.billingCycle,
|
|
fieldMap.product.internetOfferingType,
|
|
fieldMap.product.internetPlanTier,
|
|
fieldMap.product.vpnRegion,
|
|
];
|
|
|
|
return UNIQUE([...fields, ...additional]);
|
|
}
|