Skip to content

Commit

Permalink
Update API get account sales 2
Browse files Browse the repository at this point in the history
  • Loading branch information
p29hieu committed Dec 10, 2023
1 parent 1691736 commit b9493a9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
55 changes: 34 additions & 21 deletions example/console/getSalesList.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
import { FincodeService } from "../../src/server";
import { FincodeNs } from "../../src/types";

export const getSaleList = async () => {
const service = FincodeService.createInstance();
console.log(service.configData);
await service.getSaleList(
{},
{
onSuccess: console.log,
onError: console.error,
},
);
await service.getSaleItem("sales_s_22082100904_231130_00001", {
onSuccess: console.log,
onError: console.error,
});
await service.getSaleDetail(
"sales_s_22082100904_231130_00001",
{ trade_type: [1, 2] },
{
onSuccess: console.log,
onError: console.error,
},
const getFincodeSalesList = async (nextPage = 1): Promise<FincodeNs.Sale.SaleItem[]> => {
const fincode = FincodeService.createInstance();
const { current_page, last_page, list } = await fincode.getSaleList({ limit: 100, page: nextPage }, { onError: console.error });
let result: FincodeNs.Sale.SaleItem[] = list;
for (let page = current_page; page < last_page; page++) {
const res = await fincode.getSaleList({ limit: 100, page }, { onError: console.error });
result = [...res.list, ...result];
}
return result;
};

const getSaleDetailItems = async (saleId: string, nextPage = 1): Promise<FincodeNs.Sale.SaleDetailItem[]> => {
const fincode = FincodeService.createInstance();
const { current_page, last_page, list } = await fincode.getSaleDetail(
saleId,
{ limit: 100, page: nextPage, trade_type: [1, 2, 3, 4, 5] },
{ onError: console.error },
);
let result: FincodeNs.Sale.SaleDetailItem[] = list;
for (let page = current_page; page < last_page; page++) {
const res = await fincode.getSaleDetail(saleId, { limit: 100, page, trade_type: [1, 2, 3, 4, 5] }, { onError: console.error });
result = [...res.list, ...result];
}
return result;
};

export const getSaleList = async () => {
const saleList = await getFincodeSalesList();
let saleDetailList: FincodeNs.Sale.SaleDetailItem[] = [];
for (const saleItem of saleList) {
const saleDetail = await getSaleDetailItems(saleItem.id);
saleDetailList = [...saleDetailList, ...saleDetail];
}
console.log(saleDetailList);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fincode",
"version": "1.0.1",
"version": "1.0.2",
"description": "Type scripts for Fincode",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
3 changes: 1 addition & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,8 @@ export class FincodeService {
}
return data;
} catch (error) {
console.error(error.response);
if (options?.onError) {
await options.onError(error.response.data);
await options.onError(error.response?.data);
}
}
}
Expand Down

0 comments on commit b9493a9

Please sign in to comment.