Skip to content

Commit

Permalink
Introduce useUserStudentDataQuery composable
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianoertel committed Aug 20, 2024
1 parent 761def3 commit 3840229
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/composables/queries/useUserClaimsQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { FIRESTORE_COLLECTIONS } from '@/constants/firebase';
/**
* User claims data query.
*
* @param {String} userId – The user ID.
* @param {Integer} userQueryKeyIndex – The index of the query key.
* @param {QueryOptions|undefined} queryParams – Optional TanStack query options.
* @returns {UseQueryResult} The TanStack query result.
*/
Expand Down
2 changes: 0 additions & 2 deletions src/composables/queries/useUserDataQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { FIRESTORE_COLLECTIONS } from '@/constants/firebase';
/**
* User profile data query.
*
* @param {String} userId – The user ID.
* @param {Integer} userQueryKeyIndex – The index of the query key.
* @param {QueryOptions|undefined} queryParams – Optional TanStack query options.
* @returns {UseQueryResult} The TanStack query result.
*/
Expand Down
25 changes: 25 additions & 0 deletions src/composables/queries/useUserStudentDataQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useQuery } from '@tanstack/vue-query';
import { storeToRefs } from 'pinia';
import { useAuthStore } from '@/store/auth';
import { fetchDocById } from '@/helpers/query/utils';
import { USER_DATA_QUERY_KEY } from '@/constants/queryKeys';
import { FIRESTORE_COLLECTIONS } from '@/constants/firebase';

/**
* User student data query.
*
* @param {QueryOptions|undefined} queryParams – Optional TanStack query options.
* @returns {UseQueryResult} The TanStack query result.
*/
const useUserStudentDataQuery = (queryOptions = undefined) => {
const authStore = useAuthStore();
const { uid, userQueryKeyIndex } = storeToRefs(authStore);

return useQuery({
queryKey: [USER_DATA_QUERY_KEY, uid.value, userQueryKeyIndex.value],
queryFn: () => fetchDocById(FIRESTORE_COLLECTIONS.USERS, uid.value, ['studentData']),
...queryOptions,
});
};

export default useUserStudentDataQuery;

0 comments on commit 3840229

Please sign in to comment.