|
1 | 1 | const FcSubscription = require('../providers/subscription')
|
2 |
| -const assert = require('assert') |
3 |
| -const log = require('fullcube-logger') |
4 |
| -const createPromiseCallback = require('loopback-datasource-juggler/lib/utils').createPromiseCallback |
5 | 2 |
|
6 | 3 | module.exports = function SubscriptionModel(Subscription) {
|
7 |
| - Subscription.observe('fsm:oncancel', ctx => { |
8 |
| - log.debug('fsm:oncancel') |
9 |
| - return new FcSubscription(ctx.instance).cancel() |
10 |
| - .then(() => ctx) |
11 |
| - }) |
| 4 | + Subscription.observe('fsm:oncancel', ctx => new FcSubscription(ctx.instance).cancel().then(() => ctx)) |
12 | 5 |
|
13 |
| - Subscription.observe('fsm:onreactivate', ctx => { |
14 |
| - log.debug('fsm:onreactivate') |
15 |
| - return new FcSubscription(ctx.instance).reactivate() |
16 |
| - .then(() => ctx) |
17 |
| - }) |
| 6 | + Subscription.observe('fsm:onreactivate', ctx => new FcSubscription(ctx.instance).reactivate().then(() => ctx)) |
18 | 7 |
|
19 |
| - Subscription.observe('fsm:onexpire', ctx => { |
20 |
| - log.debug('fsm:onexpire') |
21 |
| - return new FcSubscription(ctx.instance).expire() |
22 |
| - .then(() => ctx) |
23 |
| - }) |
24 |
| - |
25 |
| - /** |
26 |
| - * Cancel a subscription |
27 |
| - * @param {Function(Error)} callback |
28 |
| - */ |
29 |
| - Subscription.prototype.cancel = function cancel(cb) { |
30 |
| - cb = cb || createPromiseCallback() |
31 |
| - assert(typeof cb === 'function', 'The cb argument must be a function') |
32 |
| - |
33 |
| - Subscription.app.getStateMachine(this).cancel(this) |
34 |
| - .then(res => cb(null, res)) |
35 |
| - .catch(cb) |
36 |
| - |
37 |
| - return cb.promise |
38 |
| - } |
39 |
| - |
40 |
| - /** |
41 |
| - * Reactive a canceled subscription |
42 |
| - * @param {Function(Error, )} callback |
43 |
| - */ |
44 |
| - Subscription.prototype.reactivate = function reactivate(cb) { |
45 |
| - cb = cb || createPromiseCallback() |
46 |
| - assert(typeof cb === 'function', 'The cb argument must be a function') |
47 |
| - |
48 |
| - Subscription.app.getStateMachine(this).reactivate(this) |
49 |
| - .then(res => cb(null, res)) |
50 |
| - .catch(cb) |
51 |
| - |
52 |
| - return cb.promise |
53 |
| - } |
54 |
| - |
55 |
| - /** |
56 |
| - * Expire a subscription |
57 |
| - * @param {Function(Error, )} callback |
58 |
| - */ |
59 |
| - Subscription.prototype.expire = function reactivate(cb) { |
60 |
| - cb = cb || createPromiseCallback() |
61 |
| - assert(typeof cb === 'function', 'The cb argument must be a function') |
62 |
| - |
63 |
| - Subscription.app.getStateMachine(this).expire(this) |
64 |
| - .then(res => cb(null, res)) |
65 |
| - .catch(cb) |
66 |
| - |
67 |
| - return cb.promise |
68 |
| - } |
| 8 | + Subscription.observe('fsm:onexpire', ctx => new FcSubscription(ctx.instance).expire().then(() => ctx)) |
69 | 9 | }
|
0 commit comments