1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-25 22:02:58 +03:00
guide/front/client/service/Category.ts
2019-01-22 09:04:30 +03:00

54 lines
1.2 KiB
TypeScript

import axios from 'axios'
import { ICategoryItem } from './CategoryItem'
class CategoryService {
async getCategoryById (id: ICategoryInfo['id']): Promise<ICategoryFull> {
const { data } = await axios.get(`api/category/${id}`, {})
return data
}
async getCategoryList (): Promise<ICategoryInfo[]> {
const { data } = await axios.get('api/categories', {})
return data
}
async createCategory (
{ title, group }: { title: ICategoryInfo['title'], group: ICategoryInfo['group'] }
): Promise<ICategoryInfo['id']> {
const { data } = await axios.post('api/category', null, {
params: {
title,
group
}
})
return data
}
}
export enum CategoryStatus {
finished = 'CategoryFinished',
inProgress = 'CategoryWIP',
toBeWritten = 'CategoryStub'
}
export interface ICategoryInfo {
id: string
title: string
created: string
group: string
status: CategoryStatus
}
export interface ICategoryFull {
id: string
title: string
group: string
status: CategoryStatus
description: object
items: ICategoryItem[]
}
const categoryServiceInstance = new CategoryService()
export { categoryServiceInstance as CategoryService }