Skip to content

Commit

Permalink
Added package info
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinc committed Jul 15, 2024
1 parent 96b7be2 commit f110916
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lib/**/*"
],
"main": "lib/index.js",
"version": "2.0.29",
"version": "2.0.30",
"bsb_project": true,
"devDependencies": {
"@types/assert": "^1.5.10",
Expand Down
16 changes: 12 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,25 @@ export interface APICustomerSubAccount {
description: string;
address: string;
status: ServiceStatus;
package: APICustomerSpecificPackage;
}

export interface APICustomerSpecificPackage {
id: number;
groupid: number;
action: {
id: number,
groupid: number,
actiondate: number,
cancellation: boolean
} | null
}
export interface APICustomerSpecific {
idcustomer: number;
account: string;
description: string;
aka: string;
package: {
id: number;
groupid: number;
};
package: APICustomerSpecificPackage;
value: string;
speed: string;
status: ServiceStatus;
Expand Down
28 changes: 25 additions & 3 deletions src/plugins/service-iq-enterprise/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,15 @@ export class Plugin<Meta extends object = any>
await axios.get<Array<APICustomerAccount>>(
`/api/portal/customer?email=${encodeURIComponent(email)}`,
)
).data;
).data.map(x => {
x.sub_accounts = x.sub_accounts.map(y => {
if (y.package.action && y.package.action.actiondate) {
y.package.action.actiondate = Date.parse(y.package.action.actiondate as unknown as string);
}
return y;
})
return x;
});
},
);
const getCustomerById = async (
Expand All @@ -218,6 +226,9 @@ export class Plugin<Meta extends object = any>
return null;
}
if (resp.status == 200) {
if (resp.data.package.action && resp.data.package.action.actiondate) {
resp.data.package.action.actiondate = Date.parse(resp.data.package.action.actiondate as unknown as string);
}
return resp.data;
}
throw new Error(
Expand Down Expand Up @@ -246,6 +257,12 @@ export class Plugin<Meta extends object = any>
`/api/portal/customer/account/${encodeURIComponent(id)}`,
);
if (resp.status == 200 && resp.data.account !== null) {
resp.data.sub_accounts = resp.data.sub_accounts.map(y => {
if (y.package.action && y.package.action.actiondate) {
y.package.action.actiondate = Date.parse(y.package.action.actiondate as unknown as string);
}
return y;
})
return resp.data;
}
if (resp.status == 200 && resp.data.account === null) {
Expand All @@ -269,7 +286,12 @@ export class Plugin<Meta extends object = any>
`/api/portal/customer/account/${id}/detail`,
);
if (resp.status == 200 && Tools.isArray(resp.data)) {
return resp.data;
return resp.data.map(x => {
if (x.package.action && x.package.action.actiondate) {
x.package.action.actiondate = Date.parse(x.package.action.actiondate as unknown as string);
}
return x;
});
}
throw new Error(
`Error ${resp.status}: ${resp.statusText} [${resp.data}]`,
Expand Down Expand Up @@ -318,7 +340,7 @@ export class Plugin<Meta extends object = any>
if (resp.status == 200) {
return resp.data.map(x => {
const returnObject: APIServicesResponse = {} as any;
returnObject.idgroup = Number.parseInt(x.idgroup as unknown as string);
returnObject.idgroup = typeof x.idgroup === 'number' ? x.idgroup : Number.parseInt(x.idgroup as unknown as string);
returnObject.description = x.description;
returnObject.packages = x.packages;
returnObject.installcosts = x.installcosts;
Expand Down

0 comments on commit f110916

Please sign in to comment.