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

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

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