Skip to content

Commit

Permalink
feat: members page
Browse files Browse the repository at this point in the history
  • Loading branch information
qin-guan committed Jan 6, 2024
1 parent 81857d6 commit 14f3eb7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
12 changes: 10 additions & 2 deletions composables/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
import type { User } from '~/shared/types'

const queryKeyFactory = {
user: ['user'],
currentUser: ['current-user'],
users: ['users'],
}

export function useUser() {
const firebaseCurrentUser = useCurrentUser()
return useQuery({
queryKey: queryKeyFactory.user,
queryKey: queryKeyFactory.currentUser,
queryFn: () => $api<User>(`/api/user/${firebaseCurrentUser.value?.uid}`),
enabled: computed(() => !!firebaseCurrentUser.value), // Only run when user exists
})
}

export function useUsers() {
return useQuery({
queryKey: queryKeyFactory.users,
queryFn: () => $api(`/api/user`),
})
}

export function useUserSignOutMutation() {
const auth = useFirebaseAuth()
const queryClient = useQueryClient()
Expand Down
14 changes: 11 additions & 3 deletions pages/admin/members/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<script setup lang="ts">
const { data: users } = useUsers()
</script>

<template>
<span>
Imagine something here!
</span>
<div class="p-4">
<h1 class="font-semibold text-lg">
Members
</h1>

<UTable :rows="users" />
</div>
</template>
11 changes: 10 additions & 1 deletion server/api/user/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
export default defineProtectedEventHandler((event) => {
return event.context.database.query.users.findMany()
return event.context.database.query.users.findMany({
columns: {
id: true,
memberId: true,
memberType: true,
name: true,
email: true,
graduationYear: true,
},
})
}, {
cache: {
maxAge: 60,
Expand Down

0 comments on commit 14f3eb7

Please sign in to comment.