gemcap-be-common 1.4.120 → 1.4.121
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.
|
@@ -27,14 +27,37 @@ export type ICashAllocationProductStringified = {
|
|
|
27
27
|
|
|
28
28
|
type CashAllocationProductModel = Model<ICashAllocationProduct>;
|
|
29
29
|
|
|
30
|
+
const normalizeAccountValue = (
|
|
31
|
+
value: unknown,
|
|
32
|
+
): mongoose.Types.ObjectId | 'BANK' | null => {
|
|
33
|
+
if (value === null || value === undefined || value === '') {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (value === 'BANK') {
|
|
38
|
+
return 'BANK';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (typeof value === 'string' && mongoose.isValidObjectId(value)) {
|
|
42
|
+
return new mongoose.Types.ObjectId(value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (value instanceof mongoose.Types.ObjectId) {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return null;
|
|
50
|
+
};
|
|
51
|
+
|
|
30
52
|
export const AccountSchema = {
|
|
31
53
|
type: Map,
|
|
32
54
|
of: new Schema({
|
|
33
55
|
accountId1: {
|
|
34
56
|
type: Schema.Types.Mixed,
|
|
35
57
|
required: false,
|
|
58
|
+
set: normalizeAccountValue,
|
|
36
59
|
validate: {
|
|
37
|
-
validator: function
|
|
60
|
+
validator: function(value: mongoose.Types.ObjectId | 'BANK' | null) {
|
|
38
61
|
return (
|
|
39
62
|
value === null ||
|
|
40
63
|
mongoose.isValidObjectId(value) ||
|
|
@@ -48,8 +71,9 @@ export const AccountSchema = {
|
|
|
48
71
|
accountId2: {
|
|
49
72
|
type: Schema.Types.Mixed,
|
|
50
73
|
required: false,
|
|
74
|
+
set: normalizeAccountValue,
|
|
51
75
|
validate: {
|
|
52
|
-
validator: function
|
|
76
|
+
validator: function(value: mongoose.Types.ObjectId | 'BANK' | null) {
|
|
53
77
|
return (
|
|
54
78
|
value === null ||
|
|
55
79
|
mongoose.isValidObjectId(value) ||
|