({
id,
type,
limit = DEFAULT_AWARDS_LIMIT,
}: {
id: string;
type: AwardTypes;
limit?: number;
})
| 483 | }; |
| 484 | |
| 485 | export const listAwardsInfiniteQueryOptions = ({ |
| 486 | id, |
| 487 | type, |
| 488 | limit = DEFAULT_AWARDS_LIMIT, |
| 489 | }: { |
| 490 | id: string; |
| 491 | type: AwardTypes; |
| 492 | limit?: number; |
| 493 | }) => { |
| 494 | return { |
| 495 | queryKey: generateQueryKey(RequestKey.Awards, undefined, { |
| 496 | id, |
| 497 | type, |
| 498 | first: limit, |
| 499 | }), |
| 500 | queryFn: async ({ pageParam = '' }: { pageParam?: string }) => { |
| 501 | const gqlQueryFunction = listAwardsQueryMap[type]; |
| 502 | |
| 503 | if (!gqlQueryFunction) { |
| 504 | throw new Error(`Unsupported award type: ${type}`); |
| 505 | } |
| 506 | |
| 507 | const isInitialPage = pageParam === ''; |
| 508 | |
| 509 | const gqlQuery = gqlQueryFunction({ |
| 510 | includeTotal: isInitialPage, |
| 511 | }); |
| 512 | |
| 513 | const result = await gqlClient.request<{ |
| 514 | awards: Connection<AwardListItem>; |
| 515 | awardsTotal?: LoggedUser['balance']; |
| 516 | }>(gqlQuery, { |
| 517 | id, |
| 518 | type, |
| 519 | first: limit, |
| 520 | after: pageParam, |
| 521 | }); |
| 522 | |
| 523 | // Custom mapping for source response |
| 524 | if (type === 'SQUAD') { |
| 525 | result.awards.edges = result.awards.edges.map( |
| 526 | (edge: Edge<AwardListItem>) => { |
| 527 | const newNode = edge.node as unknown as SquadAwardListItem; |
| 528 | return { |
| 529 | node: { |
| 530 | user: newNode.sender, |
| 531 | award: newNode.product, |
| 532 | awardTransaction: newNode.value, |
| 533 | }, |
| 534 | }; |
| 535 | }, |
| 536 | ); |
| 537 | } |
| 538 | |
| 539 | return result; |
| 540 | }, |
| 541 | initialPageParam: '', |
| 542 | staleTime: StaleTime.Default, |
no test coverage detected