onecore 0.1.7 → 0.3.0

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
@@ -1,113 +1,82 @@
1
1
  "use strict";
2
- var __extends =
3
- (this && this.__extends) ||
4
- (function () {
5
- var extendStatics = function (d, b) {
6
- extendStatics =
7
- Object.setPrototypeOf ||
8
- ({ __proto__: [] } instanceof Array &&
9
- function (d, b) {
10
- d.__proto__ = b;
11
- }) ||
12
- function (d, b) {
13
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
14
- };
15
- return extendStatics(d, b);
16
- };
17
- return function (d, b) {
18
- extendStatics(d, b);
19
- function __() {
20
- this.constructor = d;
21
- }
22
- d.prototype =
23
- b === null
24
- ? Object.create(b)
25
- : ((__.prototype = b.prototype), new __());
26
- };
27
- })();
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
28
15
  Object.defineProperty(exports, "__esModule", { value: true });
29
- var ViewManager = (function () {
30
- function ViewManager(r) {
16
+ var ViewUseCase = (function () {
17
+ function ViewUseCase(r) {
31
18
  this.r = r;
32
19
  this.metadata = this.metadata.bind(this);
33
20
  this.keys = this.keys.bind(this);
34
21
  this.load = this.load.bind(this);
35
22
  }
36
- ViewManager.prototype.metadata = function () {
37
- return this.r.metadata ? this.r.metadata() : undefined;
23
+ ViewUseCase.prototype.metadata = function () {
24
+ return (this.r.metadata ? this.r.metadata() : undefined);
38
25
  };
39
- ViewManager.prototype.keys = function () {
40
- return this.r.keys ? this.r.keys() : [];
26
+ ViewUseCase.prototype.keys = function () {
27
+ return (this.r.keys ? this.r.keys() : []);
41
28
  };
42
- ViewManager.prototype.load = function (id, ctx) {
29
+ ViewUseCase.prototype.load = function (id, ctx) {
43
30
  return this.r.load(id, ctx);
44
31
  };
45
- return ViewManager;
46
- })();
47
- exports.ViewManager = ViewManager;
48
- var ViewUseCase = (function (_super) {
49
- __extends(ViewUseCase, _super);
50
- function ViewUseCase() {
51
- return (_super !== null && _super.apply(this, arguments)) || this;
52
- }
53
32
  return ViewUseCase;
54
- })(ViewManager);
33
+ }());
55
34
  exports.ViewUseCase = ViewUseCase;
56
- var DefaultViewService = (function (_super) {
57
- __extends(DefaultViewService, _super);
58
- function DefaultViewService() {
59
- return (_super !== null && _super.apply(this, arguments)) || this;
35
+ var ViewManager = (function (_super) {
36
+ __extends(ViewManager, _super);
37
+ function ViewManager() {
38
+ return _super !== null && _super.apply(this, arguments) || this;
60
39
  }
61
- return DefaultViewService;
62
- })(ViewManager);
63
- exports.DefaultViewService = DefaultViewService;
64
- var ViewSearchManager = (function (_super) {
65
- __extends(ViewSearchManager, _super);
66
- function ViewSearchManager(find, repo) {
67
- var _this = _super.call(this, repo) || this;
68
- _this.find = find;
69
- _this.search = _this.search.bind(_this);
70
- return _this;
40
+ return ViewManager;
41
+ }(ViewUseCase));
42
+ exports.ViewManager = ViewManager;
43
+ var SearchUseCase = (function () {
44
+ function SearchUseCase(repo) {
45
+ this.repo = repo;
46
+ this.search = this.search.bind(this);
71
47
  }
72
- ViewSearchManager.prototype.search = function (s, limit, offset, fields) {
73
- return this.find(s, limit, offset, fields);
48
+ SearchUseCase.prototype.search = function (s, limit, page, fields) {
49
+ return this.repo.search(s, limit, page, fields);
74
50
  };
75
- return ViewSearchManager;
76
- })(ViewManager);
77
- exports.ViewSearchManager = ViewSearchManager;
51
+ return SearchUseCase;
52
+ }());
53
+ exports.SearchUseCase = SearchUseCase;
54
+ exports.SearchManager = SearchUseCase;
78
55
  var ViewSearchUseCase = (function (_super) {
79
56
  __extends(ViewSearchUseCase, _super);
80
- function ViewSearchUseCase() {
81
- return (_super !== null && _super.apply(this, arguments)) || this;
82
- }
83
- return ViewSearchUseCase;
84
- })(ViewSearchManager);
85
- exports.ViewSearchUseCase = ViewSearchUseCase;
86
- var SearchManager = (function (_super) {
87
- __extends(SearchManager, _super);
88
- function SearchManager(repository) {
89
- var _this = _super.call(this, repository) || this;
90
- _this.repository = repository;
57
+ function ViewSearchUseCase(repo) {
58
+ var _this = _super.call(this, repo) || this;
59
+ _this.repo = repo;
91
60
  _this.search = _this.search.bind(_this);
92
61
  return _this;
93
62
  }
94
- SearchManager.prototype.search = function (s, limit, offset, fields) {
95
- return this.repository.search(s, limit, offset, fields);
63
+ ViewSearchUseCase.prototype.search = function (s, limit, page, fields) {
64
+ return this.repo.search(s, limit, page, fields);
96
65
  };
97
- return SearchManager;
98
- })(ViewManager);
99
- exports.SearchManager = SearchManager;
100
- var SearchUseCase = (function (_super) {
101
- __extends(SearchUseCase, _super);
102
- function SearchUseCase() {
103
- return (_super !== null && _super.apply(this, arguments)) || this;
104
- }
105
- return SearchUseCase;
106
- })(SearchManager);
107
- exports.SearchUseCase = SearchUseCase;
108
- var GenericManager = (function (_super) {
109
- __extends(GenericManager, _super);
110
- function GenericManager(repository) {
66
+ return ViewSearchUseCase;
67
+ }(ViewUseCase));
68
+ exports.ViewSearchUseCase = ViewSearchUseCase;
69
+ var ViewSearchManger = (function (_super) {
70
+ __extends(ViewSearchManger, _super);
71
+ function ViewSearchManger() {
72
+ return _super !== null && _super.apply(this, arguments) || this;
73
+ }
74
+ return ViewSearchManger;
75
+ }(ViewSearchUseCase));
76
+ exports.ViewSearchManger = ViewSearchManger;
77
+ var GenericUseCase = (function (_super) {
78
+ __extends(GenericUseCase, _super);
79
+ function GenericUseCase(repository) {
111
80
  var _this = _super.call(this, repository) || this;
112
81
  _this.repository = repository;
113
82
  _this.create = _this.create.bind(_this);
@@ -116,171 +85,85 @@ var GenericManager = (function (_super) {
116
85
  _this.delete = _this.delete.bind(_this);
117
86
  return _this;
118
87
  }
119
- GenericManager.prototype.create = function (obj, ctx) {
88
+ GenericUseCase.prototype.create = function (obj, ctx) {
120
89
  return this.repository.create(obj, ctx);
121
90
  };
122
- GenericManager.prototype.update = function (obj, ctx) {
91
+ GenericUseCase.prototype.update = function (obj, ctx) {
123
92
  return this.repository.update(obj, ctx);
124
93
  };
125
- GenericManager.prototype.patch = function (obj, ctx) {
126
- return this.repository.patch
127
- ? this.repository.patch(obj, ctx)
128
- : Promise.resolve(-1);
94
+ GenericUseCase.prototype.patch = function (obj, ctx) {
95
+ return (this.repository.patch ? this.repository.patch(obj, ctx) : Promise.resolve(-1));
129
96
  };
130
- GenericManager.prototype.delete = function (id, ctx) {
131
- return this.repository.delete
132
- ? this.repository.delete(id, ctx)
133
- : Promise.resolve(-1);
97
+ GenericUseCase.prototype.delete = function (id, ctx) {
98
+ return (this.repository.delete ? this.repository.delete(id, ctx) : Promise.resolve(-1));
134
99
  };
135
- return GenericManager;
136
- })(ViewManager);
137
- exports.GenericManager = GenericManager;
138
- var GenericUseCase = (function (_super) {
139
- __extends(GenericUseCase, _super);
140
- function GenericUseCase() {
141
- return (_super !== null && _super.apply(this, arguments)) || this;
142
- }
143
100
  return GenericUseCase;
144
- })(GenericManager);
101
+ }(ViewUseCase));
145
102
  exports.GenericUseCase = GenericUseCase;
146
- var DefaultGenericService = (function (_super) {
147
- __extends(DefaultGenericService, _super);
148
- function DefaultGenericService() {
149
- return (_super !== null && _super.apply(this, arguments)) || this;
150
- }
151
- return DefaultGenericService;
152
- })(GenericManager);
153
- exports.DefaultGenericService = DefaultGenericService;
154
- var DefaultService = (function (_super) {
155
- __extends(DefaultService, _super);
156
- function DefaultService() {
157
- return (_super !== null && _super.apply(this, arguments)) || this;
158
- }
159
- return DefaultService;
160
- })(GenericManager);
161
- exports.DefaultService = DefaultService;
162
- var DefaultGenericSearchService = (function (_super) {
163
- __extends(DefaultGenericSearchService, _super);
164
- function DefaultGenericSearchService() {
165
- return (_super !== null && _super.apply(this, arguments)) || this;
166
- }
167
- return DefaultGenericSearchService;
168
- })(GenericManager);
169
- exports.DefaultGenericSearchService = DefaultGenericSearchService;
170
- var Manager = (function (_super) {
171
- __extends(Manager, _super);
172
- function Manager(find, repo) {
103
+ exports.GenericManager = GenericUseCase;
104
+ var UseCase = (function (_super) {
105
+ __extends(UseCase, _super);
106
+ function UseCase(find, repo) {
173
107
  var _this = _super.call(this, repo) || this;
174
108
  _this.find = find;
175
109
  _this.search = _this.search.bind(_this);
176
110
  return _this;
177
111
  }
178
- Manager.prototype.search = function (s, limit, offset, fields) {
179
- return this.find(s, limit, offset, fields);
112
+ UseCase.prototype.search = function (s, limit, page, fields) {
113
+ return this.find(s, limit, page, fields);
180
114
  };
181
- return Manager;
182
- })(GenericManager);
183
- exports.Manager = Manager;
184
- var UseCase = (function (_super) {
185
- __extends(UseCase, _super);
186
- function UseCase() {
187
- return (_super !== null && _super.apply(this, arguments)) || this;
188
- }
189
115
  return UseCase;
190
- })(Manager);
116
+ }(GenericUseCase));
191
117
  exports.UseCase = UseCase;
192
- var GenericSearchManager = (function (_super) {
193
- __extends(GenericSearchManager, _super);
194
- function GenericSearchManager() {
195
- return (_super !== null && _super.apply(this, arguments)) || this;
196
- }
197
- return GenericSearchManager;
198
- })(Manager);
199
- exports.GenericSearchManager = GenericSearchManager;
200
- var GenericSearchUseCase = (function (_super) {
201
- __extends(GenericSearchUseCase, _super);
202
- function GenericSearchUseCase() {
203
- return (_super !== null && _super.apply(this, arguments)) || this;
118
+ var Manager = (function (_super) {
119
+ __extends(Manager, _super);
120
+ function Manager() {
121
+ return _super !== null && _super.apply(this, arguments) || this;
204
122
  }
205
- return GenericSearchUseCase;
206
- })(Manager);
207
- exports.GenericSearchUseCase = GenericSearchUseCase;
123
+ return Manager;
124
+ }(UseCase));
125
+ exports.Manager = Manager;
208
126
  var SavedService = (function () {
209
- function SavedService(repository, query, max, autoRemove) {
210
- this.repository = repository;
211
- this.query = query;
127
+ function SavedService(savedRepository, max) {
128
+ this.savedRepository = savedRepository;
212
129
  this.max = max;
213
- this.autoRemove = autoRemove;
214
- this.load = this.load.bind(this);
130
+ this.isSaved = this.isSaved.bind(this);
215
131
  this.save = this.save.bind(this);
216
132
  this.remove = this.remove.bind(this);
217
133
  }
218
- SavedService.prototype.load = function (id) {
219
- var _this = this;
220
- return this.repository.load(id).then(function (items) {
221
- if (!items || items.length === 0) {
222
- return [];
223
- }
224
- return _this.query(items);
225
- });
134
+ SavedService.prototype.isSaved = function (userId, id) {
135
+ return this.savedRepository.isSaved(userId, id);
226
136
  };
227
- SavedService.prototype.save = function (id, itemId) {
137
+ SavedService.prototype.save = function (userId, id) {
228
138
  var _this = this;
229
- return this.repository.load(id).then(function (items) {
230
- if (items == null) {
231
- return _this.repository.create(id, [itemId]);
232
- } else {
233
- if (items.includes(itemId)) {
234
- return Promise.resolve(0);
235
- } else {
236
- items.push(itemId);
237
- if (items.length > _this.max) {
238
- if (_this.autoRemove) {
239
- items.shift();
240
- return _this.repository.update(id, items);
241
- } else {
242
- return Promise.resolve(-1);
243
- }
244
- } else {
245
- return _this.repository.update(id, items);
246
- }
247
- }
139
+ return this.savedRepository.count(userId).then(function (count) {
140
+ if (count >= _this.max) {
141
+ return -1;
248
142
  }
249
- });
250
- };
251
- SavedService.prototype.remove = function (id, itemId) {
252
- var _this = this;
253
- return this.repository.load(id).then(function (items) {
254
- if (items == null) {
255
- return Promise.resolve(0);
256
- } else {
257
- if (items.includes(itemId)) {
258
- items = items.filter(function (item) {
259
- return item !== itemId;
260
- });
261
- return _this.repository.update(id, items);
262
- } else {
263
- return Promise.resolve(0);
264
- }
143
+ else {
144
+ return _this.savedRepository.save(userId, id);
265
145
  }
266
146
  });
267
147
  };
148
+ SavedService.prototype.remove = function (userId, id) {
149
+ return this.savedRepository.remove(userId, id);
150
+ };
268
151
  return SavedService;
269
- })();
152
+ }());
270
153
  exports.SavedService = SavedService;
271
154
  var SavedManager = (function (_super) {
272
155
  __extends(SavedManager, _super);
273
156
  function SavedManager() {
274
- return (_super !== null && _super.apply(this, arguments)) || this;
157
+ return _super !== null && _super.apply(this, arguments) || this;
275
158
  }
276
159
  return SavedManager;
277
- })(SavedService);
160
+ }(SavedService));
278
161
  exports.SavedManager = SavedManager;
279
162
  var SavedUseCase = (function (_super) {
280
163
  __extends(SavedUseCase, _super);
281
164
  function SavedUseCase() {
282
- return (_super !== null && _super.apply(this, arguments)) || this;
165
+ return _super !== null && _super.apply(this, arguments) || this;
283
166
  }
284
167
  return SavedUseCase;
285
- })(SavedService);
168
+ }(SavedService));
286
169
  exports.SavedUseCase = SavedUseCase;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onecore",
3
- "version": "0.1.7",
3
+ "version": "0.3.0",
4
4
  "description": "onecore",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -63,6 +63,8 @@ import { GenericSearchService } from './service/GenericSearchService';
63
63
  import { GenericService } from './service/GenericService';
64
64
  import { ViewSearchService } from './service/ViewSearchService';
65
65
  import { ViewService } from './service/ViewService';
66
+ import { SearchRepository } from './repository/SearchRepository';
67
+ import { ViewSearchRepository } from './repository/ViewSearchRepository';
66
68
 
67
69
  export type Search<T, F> = (s: F, limit: number, page?: number | string, fields?: string[]) => Promise<SearchResult<T>>;
68
70
  export type SearchFunc<T, F> = Search<T, F>;
@@ -126,7 +128,7 @@ export interface ExportService {
126
128
  export interface Exporter {
127
129
  export(ctx?: any): Promise<number>;
128
130
  }
129
- export class ViewManager<T, ID> implements ViewService<T, ID> {
131
+ export class ViewUseCase<T, ID> implements ViewService<T, ID> {
130
132
  constructor(private r: ViewRepository<T, ID>) {
131
133
  this.metadata = this.metadata.bind(this);
132
134
  this.keys = this.keys.bind(this);
@@ -142,41 +144,36 @@ export class ViewManager<T, ID> implements ViewService<T, ID> {
142
144
  return this.r.load(id, ctx);
143
145
  }
144
146
  }
147
+
145
148
  // tslint:disable-next-line:max-classes-per-file
146
- export class ViewUseCase<T, ID> extends ViewManager<T, ID> {
147
- }
148
- // tslint:disable-next-line:max-classes-per-file
149
- export class DefaultViewService<T, ID> extends ViewManager<T, ID> {
149
+ export class ViewManager<T, ID> extends ViewUseCase<T, ID> {
150
150
  }
151
151
 
152
152
  // tslint:disable-next-line:max-classes-per-file
153
- export class ViewSearchManager<T, ID, F extends Filter> extends ViewManager<T, ID> implements ViewSearchService<T, ID, F> {
154
- constructor(public find: Search<T, F>, repo: ViewRepository<T, ID>) {
155
- super(repo);
153
+ export class SearchUseCase<T, F extends Filter> {
154
+ constructor(protected repo: SearchRepository<T, F>) {
156
155
  this.search = this.search.bind(this);
157
156
  }
158
157
  search(s: F, limit: number, page?: number|string, fields?: string[]): Promise<SearchResult<T>> {
159
- return this.find(s, limit, page, fields);
158
+ return this.repo.search(s, limit, page, fields);
160
159
  }
161
160
  }
161
+ export const SearchManager = SearchUseCase
162
162
  // tslint:disable-next-line:max-classes-per-file
163
- export class ViewSearchUseCase<T, ID, F extends Filter> extends ViewSearchManager<T, ID, F> {
164
- }
165
- // tslint:disable-next-line:max-classes-per-file
166
- export class SearchManager<T, ID, F extends Filter> extends ViewManager<T, ID> implements ViewSearchService<T, ID, F> {
167
- constructor(protected repository: ViewSearchService<T, ID, F>) {
168
- super(repository);
163
+ export class ViewSearchUseCase<T, ID, F extends Filter> extends ViewUseCase<T, ID> implements ViewSearchService<T, ID, F> {
164
+ constructor(protected repo: ViewSearchRepository<T, ID, Filter>) {
165
+ super(repo);
169
166
  this.search = this.search.bind(this);
170
167
  }
171
168
  search(s: F, limit: number, page?: number|string, fields?: string[]): Promise<SearchResult<T>> {
172
- return this.repository.search(s, limit, page, fields);
169
+ return this.repo.search(s, limit, page, fields);
173
170
  }
174
171
  }
175
172
  // tslint:disable-next-line:max-classes-per-file
176
- export class SearchUseCase<T, ID, F extends Filter> extends SearchManager<T, ID, F> {
173
+ export class ViewSearchManger<T, ID, F extends Filter> extends ViewSearchUseCase<T, ID, F> {
177
174
  }
178
175
  // tslint:disable-next-line:max-classes-per-file
179
- export class GenericManager<T, ID> extends ViewManager<T, ID> implements GenericService<T, ID, number> {
176
+ export class GenericUseCase<T, ID> extends ViewUseCase<T, ID> implements GenericService<T, ID, number> {
180
177
  constructor(protected repository: GenericRepository<T, ID>) {
181
178
  super(repository);
182
179
  this.create = this.create.bind(this);
@@ -197,20 +194,9 @@ export class GenericManager<T, ID> extends ViewManager<T, ID> implements Generic
197
194
  return (this.repository.delete ? this.repository.delete(id, ctx) : Promise.resolve(-1));
198
195
  }
199
196
  }
197
+ export const GenericManager = GenericUseCase
200
198
  // tslint:disable-next-line:max-classes-per-file
201
- export class GenericUseCase<T, ID> extends GenericManager<T, ID> {
202
- }
203
- // tslint:disable-next-line:max-classes-per-file
204
- export class DefaultGenericService<T, ID> extends GenericManager<T, ID> {
205
- }
206
- // tslint:disable-next-line:max-classes-per-file
207
- export class DefaultService<T, ID> extends GenericManager<T, ID> {
208
- }
209
- // tslint:disable-next-line:max-classes-per-file
210
- export class DefaultGenericSearchService<T, ID> extends GenericManager<T, ID> {
211
- }
212
- // tslint:disable-next-line:max-classes-per-file
213
- export class Manager<T, ID, F extends Filter> extends GenericManager<T, ID> implements GenericSearchService<T, ID, number, F> {
199
+ export class UseCase<T, ID, F extends Filter> extends GenericUseCase<T, ID> implements GenericSearchService<T, ID, number, F> {
214
200
  constructor(public find: Search<T, F>, repo: GenericRepository<T, ID>) {
215
201
  super(repo);
216
202
  this.search = this.search.bind(this);
@@ -220,72 +206,36 @@ export class Manager<T, ID, F extends Filter> extends GenericManager<T, ID> impl
220
206
  }
221
207
  }
222
208
  // tslint:disable-next-line:max-classes-per-file
223
- export class UseCase<T, ID, F extends Filter> extends Manager<T, ID, F> {
209
+ export class Manager<T, ID, F extends Filter> extends UseCase<T, ID, F> {
224
210
  }
225
- // tslint:disable-next-line:max-classes-per-file
226
- export class GenericSearchManager<T, ID, F extends Filter> extends Manager<T, ID, F> {
227
- }
228
- // tslint:disable-next-line:max-classes-per-file
229
- export class GenericSearchUseCase<T, ID, F extends Filter> extends Manager<T, ID, F> {
230
- }
231
- export interface SavedRepository<ID> {
232
- load(id: ID): Promise<string[]|null>;
233
- create(id: ID, arr: string[]): Promise<number>;
234
- update(id: ID, arr: string[]): Promise<number>;
211
+ export interface SavedRepository<UID, ID> {
212
+ isSaved(userId: UID, id: ID): Promise<boolean>
213
+ save(userId: UID, id: ID): Promise<number>
214
+ remove(userId: UID, id: ID): Promise<number>
215
+ count(userId: UID): Promise<number>
235
216
  }
217
+
236
218
  // tslint:disable-next-line:max-classes-per-file
237
- export class SavedService<ID, T> {
238
- constructor(protected repository: SavedRepository<ID>, protected query: (ids: string[]) => Promise<T[]>, public max: number, public autoRemove?: boolean) {
239
- this.load = this.load.bind(this);
219
+ export class SavedService<UID, ID> {
220
+ constructor(protected savedRepository: SavedRepository<UID, ID>, protected max: number) {
221
+ this.isSaved = this.isSaved.bind(this);
240
222
  this.save = this.save.bind(this);
241
223
  this.remove = this.remove.bind(this);
242
224
  }
243
- load(id: ID): Promise<T[]> {
244
- return this.repository.load(id).then(items => {
245
- if (!items || items.length === 0) {
246
- return [];
247
- }
248
- return this.query(items);
249
- });
225
+ isSaved(userId: UID, id: ID): Promise<boolean> {
226
+ return this.savedRepository.isSaved(userId, id)
250
227
  }
251
- save(id: ID, itemId: string): Promise<number> {
252
- return this.repository.load(id).then(items => {
253
- if (items == null) {
254
- return this.repository.create(id, [itemId]);
228
+ save(userId: UID, id: ID): Promise<number> {
229
+ return this.savedRepository.count(userId).then((count) => {
230
+ if (count >= this.max) {
231
+ return -1
255
232
  } else {
256
- if (items.includes(itemId)) {
257
- return Promise.resolve(0);
258
- } else {
259
- items.push(itemId);
260
- if (items.length > this.max) {
261
- if (this.autoRemove) {
262
- items.shift();
263
- return this.repository.update(id, items);
264
- } else {
265
- return Promise.resolve(-1);
266
- }
267
- } else {
268
- return this.repository.update(id, items);
269
- }
270
- }
233
+ return this.savedRepository.save(userId, id)
271
234
  }
272
- });
235
+ })
273
236
  }
274
- remove(id: ID, itemId: string): Promise<number> {
275
- return this.repository.load(id).then(items => {
276
- if (items == null) {
277
- return Promise.resolve(0);
278
- } else {
279
- if (items.includes(itemId)) {
280
- items = items.filter((item: any) => {
281
- return item !== itemId;
282
- });
283
- return this.repository.update(id, items);
284
- } else {
285
- return Promise.resolve(0);
286
- }
287
- }
288
- });
237
+ remove(userId: UID, id: ID): Promise<number> {
238
+ return this.savedRepository.remove(userId, id)
289
239
  }
290
240
  }
291
241
  // tslint:disable-next-line:max-classes-per-file
@@ -12,3 +12,9 @@ export interface Repository<T, ID> extends ViewRepository<T, ID> {
12
12
  patch(obj: Partial<T>, ctx?: any): Promise<number>;
13
13
  delete(id: ID, ctx?: any): Promise<number>;
14
14
  }
15
+ export interface CRUDRepository<T, ID> extends ViewRepository<T, ID> {
16
+ create(obj: T, ctx?: any): Promise<number>;
17
+ update(obj: T, ctx?: any): Promise<number>;
18
+ patch(obj: Partial<T>, ctx?: any): Promise<number>;
19
+ delete(id: ID, ctx?: any): Promise<number>;
20
+ }