2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 // import 'angular-resource';
23 import {IAppConfigurtaion, IMainCategory, IUserProperties} from "../models";
24 import {Categories} from "../models/categories";
26 // Define an interface of the object you want to use, providing it's properties
27 export interface ICategoryResource extends IUserProperties,ng.resource.IResource<ICategoryResource> {
30 subcategories:Array<ICategoryResource>;
32 getAllCategories(params?:Object, success?:Function, error?:Function):Categories;
33 $saveSubCategory(params?:Object, success?:Function, error?:Function):any;
34 $deleteSubCategory(params?:Object, success?:Function, error?:Function):any;
37 // Define your resource, adding the signature of the custom actions
38 export interface ICategoryResourceClass extends ng.resource.IResourceClass<ICategoryResource> {
39 getAllCategories(params?:Object, success?:Function, error?:Function):Categories;
40 saveSubCategory(params?:Object, success?:Function, error?:Function):any;
41 deleteSubCategory(params?:Object, success?:Function, error?:Function):any;
44 export class CategoryResourceService {
46 public static getResource = ($resource:ng.resource.IResourceService,
47 sdcConfig:IAppConfigurtaion):ICategoryResourceClass => {
49 // Define your custom actions here as IActionDescriptor
50 let getAllCategoriesAction:ng.resource.IActionDescriptor = {
53 url: sdcConfig.api.root + sdcConfig.api.GET_categories
55 let saveSubCategory:ng.resource.IActionDescriptor = {
58 url: sdcConfig.api.root + sdcConfig.api.POST_subcategory
60 let deleteSubCategory:ng.resource.IActionDescriptor = {
63 url: sdcConfig.api.root + sdcConfig.api.POST_subcategory
67 let url:string = sdcConfig.api.root + sdcConfig.api.POST_category;
68 let categoryResource:ICategoryResourceClass = <ICategoryResourceClass>$resource(
70 {types: '@types', categoryId: '@categoryId'},
72 getAllCategories: getAllCategoriesAction,
73 saveSubCategory: saveSubCategory,
74 deleteSubCategory: deleteSubCategory
78 return categoryResource;
81 CategoryResourceService.getResource.$inject = ['$resource', 'sdcConfig'];