промокоды запрашиваются с токеном, убран вечный цикл промокодов

This commit is contained in:
Nastya 2024-07-20 16:19:50 +03:00
parent c1aa6ab1f9
commit 937ac87c9d
2 changed files with 6 additions and 8 deletions

@ -26,7 +26,6 @@ const getPromocodeList = async (body: GetPromocodeListBody): Promise<[PromocodeL
method: "POST",
url: `${API_URL}/getList`,
body,
useToken: false,
});
return [promocodeListResponse];
@ -57,7 +56,7 @@ export const getAllPromocodes = async (): Promise<[Promocode[] | null, string?]>
const promocodes: Promocode[] = [];
let page = 0;
while (true) {
// while (true) {
const [promocodeList] = await getPromocodeList({
limit: 100,
filter: {
@ -67,12 +66,14 @@ export const getAllPromocodes = async (): Promise<[Promocode[] | null, string?]>
});
if (promocodeList) {
if (promocodeList.items.length === 0) break;
// if (promocodeList.items.length === 0) break;
if (promocodeList.items.length > 0) {
promocodes.push(...promocodeList.items);
page++;
}
}
// }
return [promocodes];
} catch (nativeError) {
@ -118,7 +119,6 @@ const createPromocode = async (body: CreatePromocodeBody): Promise<[Promocode |
method: "POST",
url: `${API_URL}/create`,
body,
useToken: false,
});
return [createPromocodeResponse];
@ -154,7 +154,6 @@ const deletePromocode = async (id: string): Promise<[null, string?]> => {
await makeRequest<never, never>({
method: "DELETE",
url: `${API_URL}/${id}`,
useToken: false,
});
return [null];
@ -175,7 +174,6 @@ const getPromocodeStatistics = async (
method: "POST",
url: `${API_URL}/stats`,
body: { id, from, to },
useToken: false,
});
return [promocodeStatisticsResponse];

@ -180,7 +180,7 @@ export function usePromocodes(
export function useAllPromocodes() {
const { data } = useSwr(
"allPromocodes",
["allPromocodes"],
async () => {
const [promocodes, promocodesError] = await promocodeApi.getAllPromocodes();