@performant-software/shared-components 0.5.1 → 0.5.4

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.
@@ -0,0 +1,35 @@
1
+ // @flow
2
+
3
+ import NestedAttributesTransform from './NestedAttributesTransform';
4
+
5
+ /**
6
+ * Class for transforming reference codes nested objects for PUT/POST requests.
7
+ */
8
+ class ReferenceCodes extends NestedAttributesTransform {
9
+ /**
10
+ * Returns the reference codes payload keys.
11
+ *
12
+ * @returns {string[]}
13
+ */
14
+ getPayloadKeys(): Array<string> {
15
+ return [
16
+ 'id',
17
+ 'name',
18
+ '_destroy'
19
+ ];
20
+ }
21
+
22
+ /**
23
+ * Calls the super method with a default value for the collection name.
24
+ *
25
+ * @param record
26
+ * @param collection
27
+ *
28
+ * @returns {{[p: string]: *}}
29
+ */
30
+ toPayload(record: any, collection: string = 'reference_codes') {
31
+ return super.toPayload(record, collection);
32
+ }
33
+ }
34
+
35
+ export default new ReferenceCodes();
@@ -0,0 +1,55 @@
1
+ // @flow
2
+
3
+ import _ from 'underscore';
4
+ import BaseTransform from './BaseTransform';
5
+ import ReferenceCodes from './ReferenceCodes';
6
+
7
+ type ReferenceTableType = {
8
+ id: number,
9
+ name: string,
10
+ key: string
11
+ };
12
+
13
+ /**
14
+ * Class for transforming reference table objects for PUT/POST requests.
15
+ */
16
+ class ReferenceTable extends BaseTransform {
17
+ /**
18
+ * Returns the reference table parameter name.
19
+ *
20
+ * @returns {string}
21
+ */
22
+ getParameterName() {
23
+ return 'reference_table';
24
+ }
25
+
26
+ /**
27
+ * Returns the reference table payload keys.
28
+ *
29
+ * @returns {string[]}
30
+ */
31
+ getPayloadKeys() {
32
+ return [
33
+ 'name',
34
+ 'key'
35
+ ];
36
+ }
37
+
38
+ /**
39
+ * Converts the passed reference table object to JSON for PUT/POST requests.
40
+ *
41
+ * @param referenceTable
42
+ *
43
+ * @returns {*}
44
+ */
45
+ toPayload(referenceTable: ReferenceTableType) {
46
+ return {
47
+ reference_table: {
48
+ ..._.pick(referenceTable, this.getPayloadKeys()),
49
+ ...ReferenceCodes.toPayload(referenceTable)
50
+ }
51
+ };
52
+ }
53
+ }
54
+
55
+ export default new ReferenceTable();