generated from Flycro/laravel-nuxt
feat: Multiple Systems
This commit is contained in:
@@ -1,26 +1,27 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export type User = {
|
||||
ulid: string;
|
||||
name: string;
|
||||
email: string;
|
||||
avatar: string;
|
||||
must_verify_email: boolean;
|
||||
has_password: boolean;
|
||||
roles: string[];
|
||||
providers: string[];
|
||||
export interface User {
|
||||
ulid: string
|
||||
name: string
|
||||
email: string
|
||||
avatar: string
|
||||
must_verify_email: boolean
|
||||
has_password: boolean
|
||||
roles: string[]
|
||||
providers: string[]
|
||||
total_votes: number
|
||||
}
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const config = useRuntimeConfig()
|
||||
const nuxtApp = useNuxtApp()
|
||||
|
||||
const user = ref(<User>{});
|
||||
const user = ref(<User>{})
|
||||
const token = useCookie('token', {
|
||||
path: '/',
|
||||
sameSite: 'strict',
|
||||
secure: config.public.apiBase.startsWith('https://'),
|
||||
maxAge: 60 * 60 * 24 * 365
|
||||
maxAge: 60 * 60 * 24 * 365,
|
||||
})
|
||||
const isLoggedIn = computed(() => !!token.value)
|
||||
|
||||
@@ -36,7 +37,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
return navigateTo('/')
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const { refresh: fetchUser } = useFetch<any>('user', {
|
||||
@@ -45,7 +46,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
if (response.status === 200) {
|
||||
user.value = response._data.user
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
return { user, isLoggedIn, logout, fetchUser, token }
|
||||
|
||||
85
nuxt/stores/book-recommendations.ts
Normal file
85
nuxt/stores/book-recommendations.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
enum BookRecommendationStatusEnum {
|
||||
PENDING = 'PENDING',
|
||||
REJECTED = 'REJECTED',
|
||||
ACTIVE = 'ACTIVE',
|
||||
COMPLETED = 'COMPLETED',
|
||||
}
|
||||
|
||||
export interface BookRecommendation {
|
||||
id: number
|
||||
book_name: string
|
||||
author: string
|
||||
description: string
|
||||
isbn: string
|
||||
pages: number
|
||||
recommended_by?: number
|
||||
recommender?: {
|
||||
ulid: number
|
||||
name: string
|
||||
email: string
|
||||
avatar: string
|
||||
}
|
||||
status: BookRecommendationStatusEnum
|
||||
cover_image?: string
|
||||
}
|
||||
|
||||
export const useBookRecommendationStore = defineStore('bookRecommendations', () => {
|
||||
const recommendations = ref<BookRecommendation[]>([])
|
||||
|
||||
const statusOptions = [
|
||||
{
|
||||
name: 'Pending',
|
||||
value: BookRecommendationStatusEnum.PENDING,
|
||||
},
|
||||
{
|
||||
name: 'Rejected',
|
||||
value: BookRecommendationStatusEnum.REJECTED,
|
||||
},
|
||||
{
|
||||
name: 'Active',
|
||||
value: BookRecommendationStatusEnum.ACTIVE,
|
||||
},
|
||||
{
|
||||
name: 'Completed',
|
||||
value: BookRecommendationStatusEnum.COMPLETED,
|
||||
},
|
||||
]
|
||||
|
||||
// Fetch all book recommendations
|
||||
const { refresh: fetchRecommendations, status: fetchRecommendationsStatus } = useFetch<BookRecommendation[]>('book-recommendations?with=recommender,votes', {
|
||||
immediate: false,
|
||||
onResponse({ response }) {
|
||||
if (response.status === 200) {
|
||||
recommendations.value = response._data
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const deleteRecommendation = async (id: number) => {
|
||||
try {
|
||||
const { error } = await useFetch(`book-recommendations/${id}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
|
||||
if (error.value) {
|
||||
console.error('Failed to delete book recommendation:', error.value)
|
||||
}
|
||||
else {
|
||||
recommendations.value = recommendations.value.filter(rec => rec.id !== id)
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error('An error occurred while deleting a book recommendation:', e)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
recommendations,
|
||||
statusOptions,
|
||||
fetchRecommendations,
|
||||
fetchRecommendationsStatus,
|
||||
deleteRecommendation,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user