onecore 0.0.39 → 0.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -112,6 +112,7 @@ var SavedService = (function () {
112
112
  this.max = max;
113
113
  this.load = this.load.bind(this);
114
114
  this.save = this.save.bind(this);
115
+ this.remove = this.remove.bind(this);
115
116
  }
116
117
  SavedService.prototype.load = function (id) {
117
118
  var _this = this;
@@ -142,6 +143,25 @@ var SavedService = (function () {
142
143
  }
143
144
  });
144
145
  };
146
+ SavedService.prototype.remove = function (id, itemId) {
147
+ var _this = this;
148
+ return this.repository.load(id).then(function (items) {
149
+ if (items == null) {
150
+ return Promise.resolve(0);
151
+ }
152
+ else {
153
+ if (items.includes(itemId)) {
154
+ items = items.filter(function (item) {
155
+ return item !== itemId;
156
+ });
157
+ return _this.repository.update(id, items);
158
+ }
159
+ else {
160
+ return Promise.resolve(0);
161
+ }
162
+ }
163
+ });
164
+ };
145
165
  return SavedService;
146
166
  }());
147
167
  exports.SavedService = SavedService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onecore",
3
- "version": "0.0.39",
3
+ "version": "0.0.40",
4
4
  "description": "onecore",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -150,6 +150,7 @@ export class SavedService<ID, T> {
150
150
  constructor(protected repository: SavedRepository<ID>, protected query: (ids: string[]) => Promise<T[]>, public max: number) {
151
151
  this.load = this.load.bind(this);
152
152
  this.save = this.save.bind(this);
153
+ this.remove = this.remove.bind(this);
153
154
  }
154
155
  load(id: ID): Promise<T[]> {
155
156
  return this.repository.load(id).then(items => {
@@ -176,4 +177,20 @@ export class SavedService<ID, T> {
176
177
  }
177
178
  });
178
179
  }
180
+ remove(id: ID, itemId: string): Promise<number> {
181
+ return this.repository.load(id).then(items => {
182
+ if (items == null) {
183
+ return Promise.resolve(0);
184
+ } else {
185
+ if (items.includes(itemId)) {
186
+ items = items.filter((item: any) => {
187
+ return item !== itemId;
188
+ });
189
+ return this.repository.update(id, items);
190
+ } else {
191
+ return Promise.resolve(0);
192
+ }
193
+ }
194
+ });
195
+ }
179
196
  }