init
This commit is contained in:
commit
fcec12e5ba
78 files changed
+9569
No files matched your search
@@ -0,0 +1,83 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import {
|
||||
type CreateIssueInput,
|
||||
type Issue,
|
||||
itemCreate,
|
||||
itemDelete,
|
||||
itemGetByKey,
|
||||
itemsList,
|
||||
itemStat,
|
||||
itemUpdate,
|
||||
type IssueStat,
|
||||
type Meta,
|
||||
type UpdateIssueInput,
|
||||
} from '@/api/issue.api.ts'
|
||||
|
||||
export const useIssueStore = defineStore('item', () => {
|
||||
const issues = ref<Issue[]>([])
|
||||
const stats = ref<IssueStat>()
|
||||
const error = ref<string | null>(null)
|
||||
const lastMeta = ref<Meta>({
|
||||
page: 1,
|
||||
totalCount: 0,
|
||||
totalPages: 0,
|
||||
})
|
||||
|
||||
async function list(params: { page: number; limit: number; text?: string | null; projectId?: string | null }) {
|
||||
try {
|
||||
const res = await itemsList(params)
|
||||
issues.value = res.list
|
||||
return res
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : 'error get list of items'
|
||||
return { list: [], meta: lastMeta.value }
|
||||
}
|
||||
}
|
||||
|
||||
async function getByKey(ckey: string) {
|
||||
try {
|
||||
const res = await itemGetByKey(ckey)
|
||||
return res
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : 'error get item by key'
|
||||
}
|
||||
}
|
||||
|
||||
async function create(input: CreateIssueInput) {
|
||||
try {
|
||||
return await itemCreate(input)
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : 'error creating issue'
|
||||
}
|
||||
}
|
||||
|
||||
async function update(id: number, input: UpdateIssueInput) {
|
||||
try {
|
||||
return await itemUpdate(id, input)
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : 'error updating issue'
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(id: number) {
|
||||
try {
|
||||
return await itemDelete(id)
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : 'error deleting issue'
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
async function getStat(): Promise<IssueStat | undefined> {
|
||||
try {
|
||||
stats.value = await itemStat()
|
||||
|
||||
return stats.value
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : 'error getting issue stat'
|
||||
}
|
||||
}
|
||||
|
||||
return { stats, list, getByKey, create, update, remove, getStat }
|
||||
})
|
||||
Reference in new issue
Block a user