1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.includeFieldIfNot = void 0;
|
4 | const lodash_1 = require("lodash");
|
5 | function includeFieldIfNot(fields, fieldToInclude) {
|
6 | if (!fields) {
|
7 | return false;
|
8 | }
|
9 | else if (Array.isArray(fields)) {
|
10 | const fieldsCloned = fields.reduce((prev, current) => ({ ...prev, [current]: true }), {});
|
11 | if (Object.keys(fieldsCloned).length > 0) {
|
12 | if (fieldsCloned[fieldToInclude] === true) {
|
13 | return false;
|
14 | }
|
15 | fieldsCloned[fieldToInclude] = true;
|
16 | return fieldsCloned;
|
17 | }
|
18 | return false;
|
19 | }
|
20 | const fieldsCloned = (0, lodash_1.cloneDeep)(fields);
|
21 | if (Object.keys(fieldsCloned).length > 0) {
|
22 | let containsTrue = false;
|
23 | for (const k in fieldsCloned) {
|
24 | if (fieldsCloned[k] === true) {
|
25 | containsTrue = true;
|
26 | }
|
27 | }
|
28 | for (const k in fieldsCloned) {
|
29 | if (k === fieldToInclude) {
|
30 | if (fieldsCloned[k] === true) {
|
31 | return false;
|
32 | }
|
33 | else {
|
34 | if (containsTrue) {
|
35 | fieldsCloned[k] = true;
|
36 | }
|
37 | else {
|
38 | delete fieldsCloned[k];
|
39 | }
|
40 | return fieldsCloned;
|
41 | }
|
42 | }
|
43 | }
|
44 | if (containsTrue) {
|
45 | fieldsCloned[fieldToInclude] = true;
|
46 | return fieldsCloned;
|
47 | }
|
48 | else {
|
49 | return false;
|
50 | }
|
51 | }
|
52 | else {
|
53 | return false;
|
54 | }
|
55 | }
|
56 | exports.includeFieldIfNot = includeFieldIfNot;
|
57 |
|
\ | No newline at end of file |