dbl-coins-invest
Version:
Sharade DBL package over other coins invest services
34 lines (29 loc) • 1.03 kB
JavaScript
import { Subscription } from "./models/subscriptions";
import DBL from "./dbl";
import AccountService from "./account";
import Rx from 'rxjs';
import * as Sequelize from "sequelize";
const Op = Sequelize.Op;
export default class SubscriptionService extends DBL {
constructor(userSub) {
if (!userSub)
throw new Error('userSub have to be provided!!!!');
super();
this.userSub = userSub;
this.model = Subscription;
this.accountServise = new AccountService(userSub);
}
createSubscription(subscription) {
return Rx.Observable.forkJoin(
this.accountServise.getUserAccount(),
this.model.create(subscription)
)
.mergeMap((response) => {
let [_account, _subscription] = response;
return Rx.Observable.fromPromise(_account.addSubscriptions(_subscription))
.map((account) => {
return _subscription;
});
});
}
}