63 lines
2.7 KiB
JavaScript
63 lines
2.7 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.prepareWhmcsClientAddressUpdate = exports.transformWhmcsClientAddress = exports.parseWhmcsClientResponse = void 0;
|
|
exports.transformWhmcsClientResponse = transformWhmcsClientResponse;
|
|
exports.transformWhmcsClient = transformWhmcsClient;
|
|
const schema_1 = require("../../schema");
|
|
const raw_types_1 = require("./raw.types");
|
|
const parseWhmcsClientResponse = (raw) => raw_types_1.whmcsClientResponseSchema.parse(raw);
|
|
exports.parseWhmcsClientResponse = parseWhmcsClientResponse;
|
|
function transformWhmcsClientResponse(response) {
|
|
const parsed = (0, exports.parseWhmcsClientResponse)(response);
|
|
return transformWhmcsClient(parsed.client);
|
|
}
|
|
function transformWhmcsClient(raw) {
|
|
return schema_1.whmcsClientSchema.parse({
|
|
...raw,
|
|
address: normalizeAddress(raw),
|
|
});
|
|
}
|
|
function normalizeAddress(client) {
|
|
const address = schema_1.addressSchema.parse({
|
|
address1: client.address1 ?? null,
|
|
address2: client.address2 ?? null,
|
|
city: client.city ?? null,
|
|
state: client.fullstate ?? client.state ?? null,
|
|
postcode: client.postcode ?? null,
|
|
country: client.country ?? null,
|
|
countryCode: client.countrycode ?? null,
|
|
phoneNumber: client.phonenumberformatted ?? client.phonenumber ?? null,
|
|
phoneCountryCode: client.phonecc ?? null,
|
|
});
|
|
const hasValues = Object.values(address).some(v => v !== undefined && v !== null && v !== "");
|
|
return hasValues ? address : undefined;
|
|
}
|
|
const transformWhmcsClientAddress = (raw) => {
|
|
const client = raw_types_1.whmcsClientSchema.parse(raw);
|
|
return normalizeAddress(client);
|
|
};
|
|
exports.transformWhmcsClientAddress = transformWhmcsClientAddress;
|
|
const prepareWhmcsClientAddressUpdate = (address) => {
|
|
const update = {};
|
|
if (address.address1 !== undefined)
|
|
update.address1 = address.address1 ?? "";
|
|
if (address.address2 !== undefined)
|
|
update.address2 = address.address2 ?? "";
|
|
if (address.city !== undefined)
|
|
update.city = address.city ?? "";
|
|
if (address.state !== undefined)
|
|
update.state = address.state ?? "";
|
|
if (address.postcode !== undefined)
|
|
update.postcode = address.postcode ?? "";
|
|
if (address.country !== undefined)
|
|
update.country = address.country ?? "";
|
|
if (address.countryCode !== undefined)
|
|
update.countrycode = address.countryCode ?? "";
|
|
if (address.phoneNumber !== undefined)
|
|
update.phonenumber = address.phoneNumber ?? "";
|
|
if (address.phoneCountryCode !== undefined)
|
|
update.phonecc = address.phoneCountryCode ?? "";
|
|
return update;
|
|
};
|
|
exports.prepareWhmcsClientAddressUpdate = prepareWhmcsClientAddressUpdate;
|
|
//# sourceMappingURL=mapper.js.map
|