generated from alphane/template
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import http from "@/api/http-client"
|
|
import {
|
|
type FiltersOptions,
|
|
type ModelOrder,
|
|
type Policy,
|
|
type WhereOptions,
|
|
} from "@/api/base-api"
|
|
|
|
export type FlashcardDeck = {
|
|
id: number
|
|
parentDeckId: number | null
|
|
creatorId: number
|
|
name: string
|
|
createdAt: string
|
|
updatedAt: string
|
|
}
|
|
|
|
export type FlashcardDeckWhereOptions = WhereOptions<FlashcardDeck, "creatorId" | "parentDeckId">
|
|
|
|
export type FlashcardDeckFiltersOptions = FiltersOptions<{
|
|
search: string | string[]
|
|
}>
|
|
|
|
export type FlashcardDeckQueryOptions = {
|
|
where?: FlashcardDeckWhereOptions
|
|
filters?: FlashcardDeckFiltersOptions
|
|
order?: ModelOrder[]
|
|
page?: number
|
|
perPage?: number
|
|
}
|
|
|
|
export const flashcardDecksApi = {
|
|
async list(params: FlashcardDeckQueryOptions = {}): Promise<{
|
|
flashcardDecks: FlashcardDeck[]
|
|
totalCount: number
|
|
}> {
|
|
const { data } = await http.get("/api/flashcard-decks", { params })
|
|
return data
|
|
},
|
|
async get(flashcardDeckId: number): Promise<{
|
|
flashcardDeck: FlashcardDeck
|
|
policy: Policy
|
|
}> {
|
|
const { data } = await http.get(`/api/flashcard-decks/${flashcardDeckId}`)
|
|
return data
|
|
},
|
|
async create(attributes: Partial<FlashcardDeck>): Promise<{
|
|
flashcardDeck: FlashcardDeck
|
|
}> {
|
|
const { data } = await http.post("/api/flashcard-decks", attributes)
|
|
return data
|
|
},
|
|
async update(
|
|
flashcardDeckId: number,
|
|
attributes: Partial<FlashcardDeck>
|
|
): Promise<{
|
|
flashcardDeck: FlashcardDeck
|
|
}> {
|
|
const { data } = await http.patch(`/api/flashcard-decks/${flashcardDeckId}`, attributes)
|
|
return data
|
|
},
|
|
async delete(flashcardDeckId: number): Promise<void> {
|
|
const { data } = await http.delete(`/api/flashcard-decks/${flashcardDeckId}`)
|
|
return data
|
|
},
|
|
}
|
|
|
|
export default flashcardDecksApi
|