- Standardized JSON and URL-encoded body parser configurations in main.ts. - Simplified method signatures in order-builder.service.ts and order-orchestrator.service.ts. - Enhanced logging format in order-item-builder.service.ts and order-validator.service.ts. - Cleaned up whitespace and formatting in various components and services for improved readability. - Updated Docker commands in manage.sh to use the new syntax.
139 lines
4.9 KiB
TypeScript
139 lines
4.9 KiB
TypeScript
import { Injectable } from "@nestjs/common";
|
|
import { CreateOrderBody, UserMapping } from "../dto/order.dto";
|
|
import { getSalesforceFieldMap } from "../../common/config/field-map";
|
|
|
|
/**
|
|
* Handles building order header data from selections
|
|
*/
|
|
@Injectable()
|
|
export class OrderBuilder {
|
|
/**
|
|
* Build order fields for Salesforce Order creation
|
|
*/
|
|
buildOrderFields(
|
|
body: CreateOrderBody,
|
|
userMapping: UserMapping,
|
|
pricebookId: string
|
|
): Record<string, unknown> {
|
|
const today = new Date().toISOString().slice(0, 10); // YYYY-MM-DD
|
|
const fields = getSalesforceFieldMap();
|
|
|
|
const orderFields: Record<string, unknown> = {
|
|
AccountId: userMapping.sfAccountId,
|
|
EffectiveDate: today,
|
|
Status: "Pending Review",
|
|
Pricebook2Id: pricebookId,
|
|
[fields.order.orderType]: body.orderType,
|
|
...(body.opportunityId ? { OpportunityId: body.opportunityId } : {}),
|
|
};
|
|
|
|
// Add activation fields
|
|
this.addActivationFields(orderFields, body);
|
|
|
|
// Add service-specific fields (only user configuration choices)
|
|
switch (body.orderType) {
|
|
case "Internet":
|
|
this.addInternetFields(orderFields, body);
|
|
break;
|
|
case "SIM":
|
|
this.addSimFields(orderFields, body);
|
|
break;
|
|
case "VPN":
|
|
this.addVpnFields(orderFields, body);
|
|
break;
|
|
}
|
|
|
|
// Add address snapshot from WHMCS (authoritative source)
|
|
// Note: We'll need to pass userId separately or get it from the userMapping
|
|
// For now, skip address snapshot until we have proper user ID access
|
|
|
|
return orderFields;
|
|
}
|
|
|
|
private addActivationFields(orderFields: Record<string, unknown>, body: CreateOrderBody): void {
|
|
const fields = getSalesforceFieldMap();
|
|
const config = body.configurations || {};
|
|
|
|
if (config.activationType) {
|
|
orderFields[fields.order.activationType] = config.activationType;
|
|
}
|
|
if (config.scheduledAt) {
|
|
orderFields[fields.order.activationScheduledAt] = config.scheduledAt;
|
|
}
|
|
orderFields[fields.order.activationStatus] = "Not Started";
|
|
}
|
|
|
|
private addInternetFields(orderFields: Record<string, unknown>, body: CreateOrderBody): void {
|
|
const fields = getSalesforceFieldMap();
|
|
const config = body.configurations || {};
|
|
|
|
// Only store user configuration choices that cannot be derived from OrderItems
|
|
if (config.accessMode) {
|
|
orderFields[fields.order.accessMode] = config.accessMode;
|
|
}
|
|
|
|
// Note: Removed fields that can be derived from OrderItems:
|
|
// - internetPlanTier: derive from service product metadata
|
|
// - installationType: derive from install product name
|
|
// - weekendInstall: derive from SKU analysis
|
|
// - hikariDenwa: derive from SKU analysis
|
|
}
|
|
|
|
private addSimFields(orderFields: Record<string, unknown>, body: CreateOrderBody): void {
|
|
const fields = getSalesforceFieldMap();
|
|
const config = body.configurations || {};
|
|
|
|
// Only store user configuration choices that cannot be derived from OrderItems
|
|
if (config.simType) {
|
|
orderFields[fields.order.simType] = config.simType;
|
|
}
|
|
if (config.eid) {
|
|
orderFields[fields.order.eid] = config.eid;
|
|
}
|
|
|
|
// Note: Removed fields that can be derived from OrderItems:
|
|
// - simVoiceMail: derive from SKU analysis
|
|
// - simCallWaiting: derive from SKU analysis
|
|
|
|
// MNP fields
|
|
if (config.isMnp === "true") {
|
|
orderFields[fields.order.mnp.application] = true;
|
|
if (config.mnpNumber) {
|
|
orderFields[fields.order.mnp.reservationNumber] = config.mnpNumber;
|
|
}
|
|
if (config.mnpExpiry) {
|
|
orderFields[fields.order.mnp.expiryDate] = config.mnpExpiry;
|
|
}
|
|
if (config.mnpPhone) {
|
|
orderFields[fields.order.mnp.phoneNumber] = config.mnpPhone;
|
|
}
|
|
if (config.mvnoAccountNumber) {
|
|
orderFields[fields.order.mnp.mvnoAccountNumber] = config.mvnoAccountNumber;
|
|
}
|
|
if (config.portingLastName) {
|
|
orderFields[fields.order.mnp.portingLastName] = config.portingLastName;
|
|
}
|
|
if (config.portingFirstName) {
|
|
orderFields[fields.order.mnp.portingFirstName] = config.portingFirstName;
|
|
}
|
|
if (config.portingLastNameKatakana) {
|
|
orderFields[fields.order.mnp.portingLastNameKatakana] = config.portingLastNameKatakana;
|
|
}
|
|
if (config.portingFirstNameKatakana) {
|
|
orderFields[fields.order.mnp.portingFirstNameKatakana] = config.portingFirstNameKatakana;
|
|
}
|
|
if (config.portingGender) {
|
|
orderFields[fields.order.mnp.portingGender] = config.portingGender;
|
|
}
|
|
if (config.portingDateOfBirth) {
|
|
orderFields[fields.order.mnp.portingDateOfBirth] = config.portingDateOfBirth;
|
|
}
|
|
}
|
|
}
|
|
|
|
private addVpnFields(orderFields: Record<string, unknown>, body: CreateOrderBody): void {
|
|
// Note: Removed vpnRegion field - can be derived from service product metadata in OrderItems
|
|
// VPN orders only need user configuration choices (none currently defined)
|
|
}
|
|
}
|