-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(history): add 3 endpoints to get histories
- Loading branch information
1 parent
ed711e7
commit 278e7c5
Showing
3 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { USER_AGENT } from "~/utils/constants"; | ||
import { createAjaxEndpoint, createEndpointURL } from "~/utils/endpoints"; | ||
|
||
export interface FinancialHistoryEvent { | ||
operation_uid: number; | ||
operationDate: number | ||
operationName: string; | ||
eWalletName: string; | ||
beneficiary_uid: number; | ||
paymentMethod: string; | ||
credit: number | null; | ||
debit: number | null; | ||
} | ||
|
||
export interface OrderHistoryEvent { | ||
order_uid: number; | ||
orderDate: number; | ||
orderReference: number; | ||
sponsorName: number; | ||
state: number; | ||
amount: number; | ||
} | ||
|
||
export interface ConsumptionHistoryEvent { | ||
consumption_uid: number; | ||
consumptionDate: number; | ||
consumptionDescription: string; | ||
amount: number; | ||
eWalletName: string; | ||
} | ||
|
||
export const getFinancialHistory = async (uid: number, startTimestamp: number, endTimestamp: number, limit: number = 30, cookies: string[]): Promise<FinancialHistoryEvent[]> => { | ||
const response = await fetch(createAjaxEndpoint(`?eID=tx_afereload_ajax_financialhistory&fe_uid=${uid}&startTimestamp=${startTimestamp}&endTimestamp=${endTimestamp}&page=1&start=0&limit=${limit}`), { | ||
headers: { "Cookie": cookies.join("; "), "User-Agent": USER_AGENT } | ||
}); | ||
|
||
const data = await response.json() as unknown as { total: number, operations: FinancialHistoryEvent[] }; | ||
|
||
return data.operations; | ||
}; | ||
|
||
export const getOrdersHistory = async (uid: number, startTimestamp: number, endTimestamp: number, limit: number = 30, cookies: string[]): Promise<OrderHistoryEvent[]> => { | ||
const response = await fetch(createAjaxEndpoint(`?eID=tx_afereload_ajax_ordershistory&fe_uid=${uid}&startTimestamp=${startTimestamp}&endTimestamp=${endTimestamp}&page=1&start=0&limit=${limit}`), { | ||
headers: { "Cookie": cookies.join("; "), "User-Agent": USER_AGENT } | ||
}); | ||
|
||
const data = await response.json() as unknown as { total: number, orders: OrderHistoryEvent[] }; | ||
return data.orders; | ||
}; | ||
|
||
export const getConsumptionsHistory = async (uid: number, startTimestamp: number, endTimestamp: number, limit: number = 30, cookies: string[]): Promise<ConsumptionHistoryEvent[]> => { | ||
const response = await fetch(createAjaxEndpoint(`?eID=tx_afereload_ajax_consumptionhistory&fe_uid=${uid}&startTimestamp=${startTimestamp}&endTimestamp=${endTimestamp}&page=1&start=0&limit=${limit}`), { | ||
headers: { "Cookie": cookies.join("; "), "User-Agent": USER_AGENT } | ||
}); | ||
|
||
const data = await response.json() as unknown as { total: number, consumptions: ConsumptionHistoryEvent[] }; | ||
return data.consumptions; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { ARD_BASE_ENDPOINT_WITH_HOST } from "~/utils/constants"; | ||
import { ARD_BASE_ENDPOINT_WITH_HOST, ARD_HOST } from "~/utils/constants"; | ||
|
||
export const createEndpointURL = (schoolID: string, path: string): string => { | ||
return `${ARD_BASE_ENDPOINT_WITH_HOST}/${schoolID}/${path}`; | ||
}; | ||
|
||
export const createAjaxEndpoint = (path: string): string => { | ||
return `${ARD_HOST}/${path}`; | ||
}; |