-
Notifications
You must be signed in to change notification settings - Fork 5
/
useAdministrationsQuery.js
31 lines (29 loc) · 1.11 KB
/
useAdministrationsQuery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { toValue } from 'vue';
import { useQuery } from '@tanstack/vue-query';
import { fetchDocsById } from '@/helpers/query/utils';
import { ADMINISTRATIONS_QUERY_KEY } from '@/constants/queryKeys';
import { FIRESTORE_COLLECTIONS } from '@/constants/firebase';
/**
* Administrations query.
*
* @param {ref<Array<String>>} administrationIds – A Vue ref containing an array of administration IDs to fetch.
* @param {QueryOptions|undefined} queryOptions – Optional TanStack query options.
* @returns {UseQueryResult} The TanStack query result.
*/
const useAdministrationsQuery = (administrationIds, queryOptions = undefined) => {
return useQuery({
queryKey: [ADMINISTRATIONS_QUERY_KEY, toValue(administrationIds)],
queryFn: () =>
fetchDocsById(
toValue(administrationIds)?.map((administrationId) => {
return {
collection: FIRESTORE_COLLECTIONS.ADMINISTRATIONS,
docId: administrationId,
select: ['name', 'publicName', 'sequential', 'assessments', 'legal'],
};
}),
),
...queryOptions,
});
};
export default useAdministrationsQuery;