1
0
mirror of https://github.com/mgerb/classic-wow-forums synced 2026-01-11 09:32:51 +00:00
Files
classic-wow-forums/client/app/services/category.service.ts
2018-01-08 22:27:21 -06:00

19 lines
559 B
TypeScript

import { cloneDeep } from 'lodash';
import axios from '../axios/axios';
import { CategoryModel } from '../model';
export class CategoryService {
private static categoryCache: CategoryModel[];
public static async getCategories(): Promise<CategoryModel[]> {
// return cache if it exists
if (CategoryService.categoryCache) {
return Promise.resolve(cloneDeep(CategoryService.categoryCache));
}
const res = await axios.get('/api/category');
CategoryService.categoryCache = cloneDeep(res.data.data);
return res.data.data;
}
}