89 lines
1.9 KiB
TypeScript
89 lines
1.9 KiB
TypeScript
import { apiClient, toQuery } from '@/lib/api-client.ts'
|
|
import type { User } from '@/api/user.api.ts'
|
|
|
|
export interface Issue {
|
|
id: number
|
|
key: string
|
|
title: string
|
|
content: string
|
|
status: 'OPEN' | 'IN_PROGRESS' | 'DONE' | 'CANCELLED'
|
|
priority: 0 | 1 | 2 | 3 | 4
|
|
assigneeId: string
|
|
reporterId: string
|
|
assignee?: User
|
|
reporter?: User
|
|
createdAt: string
|
|
updatedAt: string
|
|
}
|
|
|
|
export interface Meta {
|
|
page: number
|
|
totalCount: number
|
|
totalPages: number
|
|
}
|
|
|
|
export interface CreateIssueInput {
|
|
key: string
|
|
title: string
|
|
projectId: string
|
|
content?: string
|
|
status?: Issue['status']
|
|
priority?: Issue['priority']
|
|
assignee?: string
|
|
}
|
|
|
|
export type UpdateIssueInput = Partial<CreateIssueInput>
|
|
|
|
export interface IssueStatByStatus {
|
|
status: Issue['status']
|
|
label: string
|
|
count: number
|
|
}
|
|
|
|
export interface IssueStat {
|
|
total: number
|
|
byStatus: IssueStatByStatus[]
|
|
}
|
|
|
|
// CLIENT REQUEST
|
|
|
|
export async function itemsList(params: {
|
|
page: number
|
|
limit: number
|
|
text?: string | null
|
|
status?: string | null
|
|
assigneeId?: string | null
|
|
projectId?: string | null
|
|
}) {
|
|
const query = toQuery({
|
|
page: params.page,
|
|
limit: params.limit,
|
|
projectId: params.projectId,
|
|
text: params.text,
|
|
assigneeId: params.assigneeId,
|
|
status: params.status,
|
|
})
|
|
return apiClient.get<{ list: Issue[]; meta: Meta }>(`/api/issues/list${query}`)
|
|
}
|
|
|
|
export async function itemGetByKey(ckey: string) {
|
|
return apiClient.get<Issue>(`/api/issues/by-key/${ckey}`)
|
|
}
|
|
|
|
export async function itemCreate(input: CreateIssueInput) {
|
|
return apiClient.post<Issue>('/api/issues', input)
|
|
}
|
|
|
|
export async function itemUpdate(id: number, input: UpdateIssueInput) {
|
|
return apiClient.patch<Issue>(`/api/issues/${id}`, input)
|
|
}
|
|
|
|
export async function itemDelete(id: number) {
|
|
await apiClient.delete(`/api/issues/${id}`)
|
|
return true
|
|
}
|
|
|
|
export async function itemStat() {
|
|
return apiClient.get<IssueStat>('/api/issues/stats')
|
|
}
|