vanilli-shop-client
Advanced tools
Comparing version 1.5.7 to 1.5.8
@@ -6,2 +6,3 @@ import RootApi from "./root-api"; | ||
getCategories(): Promise<AxiosResponse>; | ||
getCategoryById(id: number): Promise<AxiosResponse>; | ||
} |
@@ -73,4 +73,11 @@ "use strict"; | ||
}; | ||
CategoryApi.prototype.getCategoryById = function (id) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, axios_1.default.get(this.endpoint + "/" + id + "?active=true")]; | ||
}); | ||
}); | ||
}; | ||
return CategoryApi; | ||
}(root_api_1.default)); | ||
exports.default = CategoryApi; |
@@ -5,4 +5,7 @@ import BaseStore from "./base-store"; | ||
categories: ICategoryDto[]; | ||
category: ICategoryDto | undefined; | ||
getCategories(): Promise<void>; | ||
getCategoryById(id: number): Promise<void>; | ||
private setCategories; | ||
private setCategory; | ||
} |
@@ -97,5 +97,33 @@ "use strict"; | ||
}; | ||
CategoryStore.prototype.getCategoryById = function (id) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, e_2; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, 3, 4]); | ||
this.startLoading(); | ||
return [4 /*yield*/, this.rootStore.categoryApi.getCategoryById(id)]; | ||
case 1: | ||
result = _a.sent(); | ||
this.setCategory(result.data); | ||
return [3 /*break*/, 4]; | ||
case 2: | ||
e_2 = _a.sent(); | ||
this.notificationStore.notifyError(e_2); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
this.finishLoading(); | ||
return [7 /*endfinally*/]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
CategoryStore.prototype.setCategories = function (categories) { | ||
this.categories = categories; | ||
}; | ||
CategoryStore.prototype.setCategory = function (category) { | ||
this.category = category; | ||
}; | ||
__decorate([ | ||
@@ -105,6 +133,12 @@ mobx_1.observable | ||
__decorate([ | ||
mobx_1.observable | ||
], CategoryStore.prototype, "category", void 0); | ||
__decorate([ | ||
mobx_1.action | ||
], CategoryStore.prototype, "setCategories", null); | ||
__decorate([ | ||
mobx_1.action | ||
], CategoryStore.prototype, "setCategory", null); | ||
return CategoryStore; | ||
}(base_store_1.default)); | ||
exports.default = CategoryStore; |
{ | ||
"name": "vanilli-shop-client", | ||
"version": "1.5.7", | ||
"version": "1.5.8", | ||
"description": "Client for Vanilli Shop API", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -10,2 +10,6 @@ import RootApi from "./root-api"; | ||
} | ||
async getCategoryById(id: number): Promise<AxiosResponse> { | ||
return Axios.get(`${this.endpoint}/${id}?active=true`); | ||
} | ||
} |
@@ -9,2 +9,5 @@ import BaseStore from "./base-store"; | ||
@observable | ||
category: ICategoryDto | undefined; | ||
async getCategories() { | ||
@@ -22,2 +25,14 @@ try { | ||
async getCategoryById(id: number) { | ||
try { | ||
this.startLoading(); | ||
const result = await this.rootStore.categoryApi.getCategoryById(id); | ||
this.setCategory(result.data); | ||
} catch (e) { | ||
this.notificationStore.notifyError(e); | ||
} finally { | ||
this.finishLoading(); | ||
} | ||
} | ||
@action | ||
@@ -27,2 +42,7 @@ private setCategories(categories: ICategoryDto[]) { | ||
} | ||
@action | ||
private setCategory(category: ICategoryDto) { | ||
this.category = category; | ||
} | ||
} |
264724
5867