({
id,
type,
limit = DEFAULT_AWARDS_LIMIT,
}: {
id: string;
type: AwardTypes;
limit?: number;
})
| 464 | }; |
| 465 | |
| 466 | export const listAwardsInfiniteQueryOptions = ({ |
| 467 | id, |
| 468 | type, |
| 469 | limit = DEFAULT_AWARDS_LIMIT, |
| 470 | }: { |
| 471 | id: string; |
| 472 | type: AwardTypes; |
| 473 | limit?: number; |
| 474 | }) => { |
| 475 | return { |
| 476 | queryKey: generateQueryKey(RequestKey.Awards, undefined, { |
| 477 | id, |
| 478 | type, |
| 479 | first: limit, |
| 480 | }), |
| 481 | queryFn: async ({ pageParam = '' }: { pageParam?: string }) => { |
| 482 | const gqlQueryFunction = listAwardsQueryMap[type]; |
| 483 | |
| 484 | if (!gqlQueryFunction) { |
| 485 | throw new Error(`Unsupported award type: ${type}`); |
| 486 | } |
| 487 | |
| 488 | const isInitialPage = pageParam === ''; |
| 489 | |
| 490 | const gqlQuery = gqlQueryFunction({ |
| 491 | includeTotal: isInitialPage, |
| 492 | }); |
| 493 | |
| 494 | const result = await gqlClient.request<{ |
| 495 | awards: Connection<AwardListItem>; |
| 496 | awardsTotal?: LoggedUser['balance']; |
| 497 | }>(gqlQuery, { |
| 498 | id, |
| 499 | type, |
| 500 | first: limit, |
| 501 | after: pageParam, |
| 502 | }); |
| 503 | |
| 504 | // Custom mapping for source response |
| 505 | if (type === 'SQUAD') { |
| 506 | result.awards.edges = result.awards.edges.map( |
| 507 | (edge: Edge<AwardListItem>) => { |
| 508 | const newNode = edge.node as unknown as SquadAwardListItem; |
| 509 | return { |
| 510 | node: { |
| 511 | user: newNode.sender, |
| 512 | award: newNode.product, |
| 513 | awardTransaction: newNode.value, |
| 514 | }, |
| 515 | }; |
| 516 | }, |
| 517 | ); |
| 518 | } |
| 519 | |
| 520 | return result; |
| 521 | }, |
| 522 | initialPageParam: '', |
| 523 | staleTime: StaleTime.Default, |
no test coverage detected