-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add book user store and notification email setting
- Loading branch information
1 parent
0983896
commit a6e0259
Showing
3 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { defineStore, storeToRefs } from 'pinia' | ||
import { useBookStoreApiStore } from './book-store-api' | ||
import { LIKE_CO_API } from '~/constant' | ||
|
||
export const useUserStore = defineStore('user', () => { | ||
const bookStoreApiStore = useBookStoreApiStore() | ||
const { token } = storeToRefs(bookStoreApiStore) | ||
|
||
const bookUser = ref(null as any) | ||
|
||
async function fetchBookUserProfile () { | ||
const { error, data } = await useFetch( | ||
`${LIKE_CO_API}/likernft/book/user/profile`, | ||
{ | ||
headers: { | ||
authorization: `Bearer ${token.value}` | ||
} | ||
} | ||
) | ||
if (error.value) { | ||
throw error.value | ||
} | ||
bookUser.value = data.value | ||
return bookUser.value | ||
} | ||
|
||
function lazyFetchBookUserProfile () { | ||
if (bookUser.value) { | ||
return bookUser.value | ||
} | ||
return fetchBookUserProfile() | ||
} | ||
|
||
async function updateBookUserProfile (payload: any) { | ||
const { error } = await useFetch(`${LIKE_CO_API}/likernft/book/user/profile`, { | ||
method: 'POST', | ||
body: payload, | ||
headers: { | ||
authorization: `Bearer ${token.value}` | ||
} | ||
}) | ||
if (error.value) { | ||
throw error.value | ||
} | ||
bookUser.value = { ...bookUser.value, ...payload } | ||
return bookUser.value | ||
} | ||
|
||
return { | ||
bookUser, | ||
fetchBookUserProfile, | ||
lazyFetchBookUserProfile, | ||
updateBookUserProfile | ||
} | ||
}) |