UNPKG

1.87 kBPlain TextView Raw
1/**
2 * @hidden
3 */
4
5/**
6 */
7//
8// Pending approvals listing object
9// Lists pending approvals and get pending approval objects
10//
11// Copyright 2015, BitGo, Inc. All Rights Reserved.
12//
13
14import * as Bluebird from 'bluebird';
15import * as _ from 'lodash';
16
17import { common } from '@bitgo/sdk-core';
18const PendingApproval = require('./pendingapproval');
19
20//
21// Constructor
22//
23const PendingApprovals = function (bitgo) {
24 this.bitgo = bitgo;
25};
26
27//
28// list
29// List the pending approvals available to the user
30//
31PendingApprovals.prototype.list = function (params, callback) {
32 params = params || {};
33 common.validateParams(params, [], ['walletId', 'enterpriseId'], callback);
34
35 const queryParams: any = {};
36 if (_.isString(params.walletId)) {
37 queryParams.walletId = params.walletId;
38 }
39 if (_.isString(params.enterpriseId)) {
40 queryParams.enterprise = params.enterpriseId;
41 }
42
43 if (Object.keys(queryParams).length !== 1) {
44 throw new Error('must provide exactly 1 of walletId or enterpriseId to get pending approvals on');
45 }
46
47 const self = this;
48 return Bluebird.resolve(
49 this.bitgo.get(this.bitgo.url('/pendingapprovals')).query(queryParams).result()
50 ).then(function (body) {
51 body.pendingApprovals = body.pendingApprovals.map(function (p) { return new PendingApproval(self.bitgo, p); });
52 return body;
53 }).nodeify(callback);
54};
55
56//
57// get
58// Fetch an existing pending approval
59// Parameters include:
60// id: the pending approval id
61//
62PendingApprovals.prototype.get = function (params, callback) {
63 params = params || {};
64 common.validateParams(params, ['id'], [], callback);
65
66 const self = this;
67 return Bluebird.resolve(
68 this.bitgo.get(this.bitgo.url('/pendingapprovals/' + params.id)).result()
69 ).then(function (body) {
70 return new PendingApproval(self.bitgo, body);
71 }).nodeify(callback);
72};
73
74export = PendingApprovals;