@barchart/portfolio-api-common 1.2.12 → 1.2.13

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.
@@ -73,6 +73,28 @@ module.exports = (() => {
73
73
  return valid.map(d => d.type);
74
74
  }
75
75
 
76
+ /**
77
+ * Returns transaction types which can be initiated by the user, regardless
78
+ * of instrument type.
79
+ *
80
+ * @public
81
+ * @static
82
+ * @return {Array.<TransactionType>}
83
+ */
84
+ static getUserInitiatedTransactionTypes() {
85
+ return array.unique(Object.keys(validTransactionTypes).reduce((types, key) => {
86
+ const instrumentTypes = validTransactionTypes[key];
87
+
88
+ instrumentTypes.forEach((data) => {
89
+ if (data.user) {
90
+ types.push(data.type);
91
+ }
92
+ });
93
+
94
+ return types;
95
+ }, [ ]));
96
+ }
97
+
76
98
  /**
77
99
  * Checks to see if an transaction type is applicable to an instrument type.
78
100
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.12",
3
+ "version": "1.2.13",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -1062,6 +1062,28 @@ module.exports = (() => {
1062
1062
  return valid.map(d => d.type);
1063
1063
  }
1064
1064
 
1065
+ /**
1066
+ * Returns transaction types which can be initiated by the user, regardless
1067
+ * of instrument type.
1068
+ *
1069
+ * @public
1070
+ * @static
1071
+ * @return {Array.<TransactionType>}
1072
+ */
1073
+ static getUserInitiatedTransactionTypes() {
1074
+ return array.unique(Object.keys(validTransactionTypes).reduce((types, key) => {
1075
+ const instrumentTypes = validTransactionTypes[key];
1076
+
1077
+ instrumentTypes.forEach((data) => {
1078
+ if (data.user) {
1079
+ types.push(data.type);
1080
+ }
1081
+ });
1082
+
1083
+ return types;
1084
+ }, [ ]));
1085
+ }
1086
+
1065
1087
  /**
1066
1088
  * Checks to see if an transaction type is applicable to an instrument type.
1067
1089
  *
@@ -9226,6 +9248,20 @@ describe('When validating transaction order', () => {
9226
9248
  });
9227
9249
  });
9228
9250
 
9251
+ describe('When requesting all the user-initiated transaction types', () => {
9252
+ 'use strict';
9253
+
9254
+ let userInitiated;
9255
+
9256
+ beforeEach(() => {
9257
+ userInitiated = TransactionValidator.getUserInitiatedTransactionTypes();
9258
+ });
9259
+
9260
+ it('Only nine types should be returned', () => {
9261
+ expect(userInitiated.length).toEqual(9);
9262
+ });
9263
+ });
9264
+
9229
9265
  },{"./../../../lib/data/TransactionValidator":5,"@barchart/common-js/lang/Day":18}],37:[function(require,module,exports){
9230
9266
  const Currency = require('@barchart/common-js/lang/Currency'),
9231
9267
  Decimal = require('@barchart/common-js/lang/Decimal');
@@ -41,3 +41,17 @@ describe('When validating transaction order', () => {
41
41
  expect(TransactionValidator.validateOrder([ build(1, '2018-05-02'), build(2, '2018-05-01'), build(3, '2018-04-30') ])).toEqual(false);
42
42
  });
43
43
  });
44
+
45
+ describe('When requesting all the user-initiated transaction types', () => {
46
+ 'use strict';
47
+
48
+ let userInitiated;
49
+
50
+ beforeEach(() => {
51
+ userInitiated = TransactionValidator.getUserInitiatedTransactionTypes();
52
+ });
53
+
54
+ it('Only nine types should be returned', () => {
55
+ expect(userInitiated.length).toEqual(9);
56
+ });
57
+ });