whmcs getclients array fix

This commit is contained in:
T. Narantuya 2025-08-28 18:57:12 +09:00
parent d00c47f41e
commit a68df81aee
4 changed files with 22 additions and 26 deletions

View File

@ -75,7 +75,8 @@ COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
COPY packages/shared/package.json ./packages/shared/
COPY apps/bff/package.json ./apps/bff/
# Install only production dependencies
# Install only production dependencies; run scripts (needed for bcrypt/prisma) but disable Husky
ENV HUSKY=0
RUN pnpm install --frozen-lockfile --prod
# Copy built applications and Prisma client

View File

@ -258,18 +258,12 @@ export class AuthService {
}
// 3. Extract Customer Number from field ID 198
const customerNumberField = clientDetails.customfields?.customfield.find(
field => field.id == 198
);
const customerNumberField = clientDetails.customfields?.find(field => field.id === 198);
const customerNumber = customerNumberField?.value?.trim();
const customerNumber = customerNumberField?.value as string;
if (!customerNumber || customerNumber.toString().trim() === "") {
if (!customerNumber) {
throw new BadRequestException(
`Customer Number not found in WHMCS custom field 198. ` +
`Found field: ${JSON.stringify(customerNumberField)}. ` +
`Available custom fields: ${JSON.stringify(clientDetails.customfields || [])}. ` +
`Please contact support.`
`Customer Number not found in WHMCS custom field 198. Please contact support.`
);
}

View File

@ -14,7 +14,7 @@ import {
import {
WhmcsInvoice,
WhmcsProduct,
WhmcsCustomFields,
WhmcsCustomField,
WhmcsInvoiceItems,
WhmcsPaymentMethod,
WhmcsPaymentGateway,
@ -147,15 +147,15 @@ export class WhmcsDataTransformer {
* Transform custom fields from WHMCS format
*/
private transformCustomFields(
customFields?: WhmcsCustomFields
customFields?: WhmcsCustomField[]
): Record<string, string> | undefined {
if (!customFields?.customfield || !Array.isArray(customFields.customfield)) {
if (!customFields || !Array.isArray(customFields)) {
return undefined;
}
const result: Record<string, string> = {};
customFields.customfield.forEach(field => {
customFields.forEach(field => {
if (field.name && field.value) {
result[field.name] = field.value;
}

View File

@ -38,21 +38,22 @@ export interface WhmcsClientResponse {
datecreated: string;
lastattempt?: string;
lastlogin?: string;
customfields?: WhmcsCustomFields;
customfields?: WhmcsCustomField[];
};
}
// Custom Fields Structure
export interface WhmcsCustomFields {
customfield: Array<{
id: number;
name: string;
translated_name: string;
value: string;
type: string;
}>;
// Custom Field Structure - Based on official WHMCS API documentation
export interface WhmcsCustomField {
id: number;
value: string;
// Legacy fields that may appear in some responses
name?: string;
translated_name?: string;
type?: string;
}
// Invoice Types
export interface WhmcsInvoicesResponse {
invoices: {
@ -153,7 +154,7 @@ export interface WhmcsProduct {
packageid?: number;
packagename?: string;
configoptions?: Record<string, unknown>;
customfields?: WhmcsCustomFields;
customfields?: WhmcsCustomField[];
firstpaymentamount: string;
recurringamount: string;
paymentmethod: string;