PageSourceSearch

https://retainyourbrain.com/services/storage/category.service.js

js retainyourbrain.com collected 2026-09-28 08:36:46 UTC 2,379 bytes, 80 lines download raw bytes

1(function () {
2  'use strict'
3
4  angular.module('saddleApp.services').service('categoryService', ['requestFactory', function (requestFactory) {
5	  const path = 'category'
6    let categoryService = {}
7
8    var categories = []
9    var lastCallParams = null
10    categoryService.getAll = function (params = {}, cache = false) {
11      
12      return new Promise(function (resolve, reject) {
13        if (JSON.stringify(params) === JSON.stringify(lastCallParams)) {
14          resolve(categories)
15          return
16        }
17        requestFactory.getAll(path, params, cache).then(function (response) {
18          categories = response.data
19          lastCallParams = params
20          resolve(categories)
21        }).catch(function (error) {
22          reject(error)
23        })
24      })
25    }
26
27    categoryService.post = function (data) {
28      return new Promise(function (resolve, reject) {
29        requestFactory.post(path, data).then(function (response) {
30          if (response.status === 201) {
31            data.id = response.data.insertId
32            categories.push(data)
33          }
34          resolve(response)
35        }).catch(function (error) {
36          reject(error)
37        })
38      })
39    }
40
41    categoryService.put = function (data) {
42      return new Promise(function (resolve, reject) {
43        requestFactory.put(path, data).then(function (response) {
44          if (response.status === 204) {
45            categories = categories.map(function (category) {
46              if (category.id === data.id) {
47                Object.keys(data).forEach(function(key) {
48                  if(data[key] !== '') {
49                    category[key] = data[key];
50                  }
51                });
52              }
53              return category;
54            })
55          }
56          resolve(response);
57        }).catch(function (error) {
58          reject(error);
59        })
60      }) 
61    }
62
63    categoryService.delete = function (id) {
64      return new Promise(function (resolve, reject) {
65        requestFactory.delete(path, id).then(function (response) {
66          if(response.data === 'deleted') {
67            categories = categories.filter(function (category) {
68              return category.id !== id;
69            });
70          }
71          resolve(response);
72        }).catch(function (error) {
73          reject(error)
74        })
75      })
76    }
77
78	return categoryService;
79  }])
80})()

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.