@carecard/validate 3.1.16 → 3.1.18

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.
@@ -1,232 +1,232 @@
1
1
  // Validate the property values format.
2
2
  const {
3
- isEmailString,
4
- isPhoneNumber,
5
- isUrlSafeString,
6
- isValidUuidString,
7
- isSimplePasswordString,
8
- isPasswordString,
9
- isString6To16CharacterLong,
10
- isNameString,
11
- isSafeSearchString,
12
- isCharactersString,
13
- isValidIntegerString,
14
- isValidJsonString,
15
- isImageUrl,
16
- isValidDomainName,
17
- isValidTimestampzString,
18
- isValidTimestampString,
19
- isBoolValue,
20
- isValidUrl,
21
- isValidArrayOfStrings,
3
+ isEmailString,
4
+ isPhoneNumber,
5
+ isUrlSafeString,
6
+ isValidUuidString,
7
+ isSimplePasswordString,
8
+ isPasswordString,
9
+ isString6To16CharacterLong,
10
+ isNameString,
11
+ isSafeSearchString,
12
+ isCharactersString,
13
+ isValidIntegerString,
14
+ isValidJsonString,
15
+ isImageUrl,
16
+ isValidDomainName,
17
+ isValidTimestampzString,
18
+ isValidTimestampString,
19
+ isBoolValue,
20
+ isValidUrl,
21
+ isValidArrayOfStrings,
22
22
  } = require('./validate');
23
23
 
24
24
  function validateProperties(obj = {}) {
25
- const returnObj = {};
25
+ const returnObj = {};
26
26
 
27
- for (const [key, value] of Object.entries(obj || {})) {
28
- switch (key) {
29
- case 'first_name':
30
- case 'firstName':
31
- case 'last_name':
32
- case 'lastName':
33
- case 'username':
34
- case 'new_status':
35
- case 'newStatus':
36
- case 'description':
37
- case 'comment':
38
- case 'status':
39
- case 'name':
40
- case 'title':
41
- case 'brand':
42
- case 'short_description':
43
- case 'shortDescription':
44
- case 'college_name':
45
- case 'collegeName':
46
- case 'campus_name':
47
- case 'campusName':
48
- case 'role':
49
- case 'role_id':
50
- case 'roleId':
51
- case 'campus':
52
- case 'institution_name':
53
- case 'institutionName':
54
- case 'program_name':
55
- case 'programName':
56
- case 'role_name':
57
- case 'roleName':
58
- case 'document_type':
59
- case 'documentType':
60
- case 'reason':
61
- case 'street':
62
- case 'city':
63
- case 'state':
64
- case 'country':
65
- case 'type':
66
- if (isNameString(value) || (typeof value === 'object' && value !== null)) {
67
- returnObj[key] = value;
68
- }
69
- break;
70
- case 'postal_code':
71
- case 'postalCode':
72
- if (isCharactersString(value)) {
73
- returnObj[key] = value;
74
- }
75
- break;
27
+ for (const [key, value] of Object.entries(obj || {})) {
28
+ switch (key) {
29
+ case 'first_name':
30
+ case 'firstName':
31
+ case 'last_name':
32
+ case 'lastName':
33
+ case 'username':
34
+ case 'new_status':
35
+ case 'newStatus':
36
+ case 'description':
37
+ case 'comment':
38
+ case 'status':
39
+ case 'name':
40
+ case 'title':
41
+ case 'brand':
42
+ case 'short_description':
43
+ case 'shortDescription':
44
+ case 'college_name':
45
+ case 'collegeName':
46
+ case 'campus_name':
47
+ case 'campusName':
48
+ case 'role':
49
+ case 'role_id':
50
+ case 'roleId':
51
+ case 'campus':
52
+ case 'institution_name':
53
+ case 'institutionName':
54
+ case 'program_name':
55
+ case 'programName':
56
+ case 'role_name':
57
+ case 'roleName':
58
+ case 'document_type':
59
+ case 'documentType':
60
+ case 'reason':
61
+ case 'street':
62
+ case 'city':
63
+ case 'state':
64
+ case 'country':
65
+ case 'type':
66
+ if (isNameString(value)) {
67
+ returnObj[key] = value;
68
+ }
69
+ break;
70
+ case 'postal_code':
71
+ case 'postalCode':
72
+ if (isCharactersString(value)) {
73
+ returnObj[key] = value;
74
+ }
75
+ break;
76
76
 
77
- case 'is_primary':
78
- case 'isPrimary':
79
- if (isBoolValue(value)) {
80
- returnObj[key] = value;
81
- }
82
- break;
83
- case 'search_string':
84
- case 'searchString':
85
- if (isSafeSearchString(value)) {
86
- returnObj[key] = value;
87
- }
88
- break;
89
- case 'password':
90
- case 'new_password':
91
- case 'newPassword':
92
- if (isString6To16CharacterLong(value) && isSimplePasswordString(value)) {
93
- returnObj[key] = value;
94
- }
95
- break;
96
- case 'strong_password':
97
- case 'strongPassword':
98
- if (isString6To16CharacterLong(value) && isPasswordString(value)) {
99
- returnObj[key] = value;
100
- }
101
- break;
102
- case 'email':
103
- if (isEmailString(value)) {
104
- returnObj[key] = value;
105
- }
106
- break;
107
- case 'phone_number':
108
- case 'phoneNumber':
109
- if (isPhoneNumber(value)) {
110
- returnObj[key] = value;
111
- }
112
- break;
113
- case 'token':
114
- case 'email_confirm_token':
115
- case 'emailConfirmToken':
116
- case 'verification_token':
117
- case 'verificationToken':
118
- if (isUrlSafeString(value)) {
119
- returnObj[key] = value;
120
- }
121
- break;
122
- case 'uuid':
123
- case 'item_id':
124
- case 'user_id':
125
- case 'address_id':
126
- case 'addressId':
127
- case 'image_id':
128
- case 'itemId':
129
- case 'userId':
130
- case 'imageId':
131
- case 'order_id':
132
- case 'orderId':
133
- case 'category_id':
134
- case 'categoryId':
135
- case 'parent_id':
136
- case 'parentId':
137
- case 'college_id':
138
- case 'collegeId':
139
- case 'campus_id':
140
- case 'campusId':
141
- case 'program_id':
142
- case 'programId':
143
- case 'id':
144
- case 'institution_id':
145
- case 'institutionId':
146
- case 'role_assignment_id':
147
- case 'roleAssignmentId':
148
- case 'user_role_id':
149
- case 'userRoleId':
150
- case 'phone_number_id':
151
- case 'phoneNumberId':
152
- if (isValidUuidString(value)) {
153
- returnObj[key] = value;
154
- }
155
- break;
156
- case 'period':
157
- if (isCharactersString(value)) {
158
- returnObj[key] = value;
159
- }
160
- break;
161
- case 'offset_number':
162
- case 'offsetNumber':
163
- case 'number_of_orders':
164
- case 'numberOfOrders':
165
- case 'price':
166
- case 'from':
167
- case 'number':
168
- if (isValidIntegerString(value)) {
169
- returnObj[key] = value;
170
- }
171
- break;
172
- case 'about':
173
- if (isValidJsonString(value)) {
174
- returnObj[key] = value.trim();
175
- }
176
- break;
177
- case 'weight':
178
- case 'dimensions':
179
- case 'permission':
180
- case 'scope_data':
181
- case 'scopeData':
182
- case 'meta_data':
183
- case 'metaData':
184
- if (isValidJsonString(JSON.stringify(value))) {
185
- returnObj[key] = value;
186
- }
187
- break;
188
- case 'aliases':
189
- if (isValidArrayOfStrings(value)) {
190
- returnObj[key] = value;
191
- }
192
- break;
193
- case 'image_url':
194
- case 'imageUrl':
195
- case 'website':
196
- case 'file_url':
197
- case 'fileUrl':
198
- if (isImageUrl(value) || isValidUrl(value)) {
199
- returnObj[key] = value;
200
- }
201
- break;
202
- case 'domain_name':
203
- case 'domainName':
204
- case 'domain':
205
- case 'email_domain':
206
- case 'emailDomain':
207
- case 'email_domain_name':
208
- case 'emailDomainName':
209
- if (isValidDomainName(value)) {
210
- returnObj[key] = value;
211
- }
212
- break;
213
- case 'expires_at':
214
- case 'expiresAt':
215
- if (isValidTimestampzString(value) || isValidTimestampString(value)) {
216
- returnObj[key] = value;
217
- }
218
- break;
219
- case 'active':
220
- if (isBoolValue(value)) {
221
- returnObj[key] = value;
77
+ case 'is_primary':
78
+ case 'isPrimary':
79
+ if (isBoolValue(value)) {
80
+ returnObj[key] = value;
81
+ }
82
+ break;
83
+ case 'search_string':
84
+ case 'searchString':
85
+ if (isSafeSearchString(value)) {
86
+ returnObj[key] = value;
87
+ }
88
+ break;
89
+ case 'password':
90
+ case 'new_password':
91
+ case 'newPassword':
92
+ if (isString6To16CharacterLong(value) && isSimplePasswordString(value)) {
93
+ returnObj[key] = value;
94
+ }
95
+ break;
96
+ case 'strong_password':
97
+ case 'strongPassword':
98
+ if (isString6To16CharacterLong(value) && isPasswordString(value)) {
99
+ returnObj[key] = value;
100
+ }
101
+ break;
102
+ case 'email':
103
+ if (isEmailString(value)) {
104
+ returnObj[key] = value;
105
+ }
106
+ break;
107
+ case 'phone_number':
108
+ case 'phoneNumber':
109
+ if (isPhoneNumber(value)) {
110
+ returnObj[key] = value;
111
+ }
112
+ break;
113
+ case 'token':
114
+ case 'email_confirm_token':
115
+ case 'emailConfirmToken':
116
+ case 'verification_token':
117
+ case 'verificationToken':
118
+ if (isUrlSafeString(value)) {
119
+ returnObj[key] = value;
120
+ }
121
+ break;
122
+ case 'uuid':
123
+ case 'item_id':
124
+ case 'user_id':
125
+ case 'address_id':
126
+ case 'addressId':
127
+ case 'image_id':
128
+ case 'itemId':
129
+ case 'userId':
130
+ case 'imageId':
131
+ case 'order_id':
132
+ case 'orderId':
133
+ case 'category_id':
134
+ case 'categoryId':
135
+ case 'parent_id':
136
+ case 'parentId':
137
+ case 'college_id':
138
+ case 'collegeId':
139
+ case 'campus_id':
140
+ case 'campusId':
141
+ case 'program_id':
142
+ case 'programId':
143
+ case 'id':
144
+ case 'institution_id':
145
+ case 'institutionId':
146
+ case 'role_assignment_id':
147
+ case 'roleAssignmentId':
148
+ case 'user_role_id':
149
+ case 'userRoleId':
150
+ case 'phone_number_id':
151
+ case 'phoneNumberId':
152
+ if (isValidUuidString(value)) {
153
+ returnObj[key] = value;
154
+ }
155
+ break;
156
+ case 'period':
157
+ if (isCharactersString(value)) {
158
+ returnObj[key] = value;
159
+ }
160
+ break;
161
+ case 'offset_number':
162
+ case 'offsetNumber':
163
+ case 'number_of_orders':
164
+ case 'numberOfOrders':
165
+ case 'price':
166
+ case 'from':
167
+ case 'number':
168
+ if (isValidIntegerString(value)) {
169
+ returnObj[key] = value;
170
+ }
171
+ break;
172
+ case 'about':
173
+ if (isValidJsonString(value)) {
174
+ returnObj[key] = value;
175
+ }
176
+ break;
177
+ case 'weight':
178
+ case 'dimensions':
179
+ case 'permission':
180
+ case 'scope_data':
181
+ case 'scopeData':
182
+ case 'meta_data':
183
+ case 'metaData':
184
+ if (isValidJsonString(JSON.stringify(value))) {
185
+ returnObj[key] = value;
186
+ }
187
+ break;
188
+ case 'aliases':
189
+ if (isValidArrayOfStrings(value)) {
190
+ returnObj[key] = value;
191
+ }
192
+ break;
193
+ case 'image_url':
194
+ case 'imageUrl':
195
+ case 'website':
196
+ case 'file_url':
197
+ case 'fileUrl':
198
+ if (isImageUrl(value) || isValidUrl(value)) {
199
+ returnObj[key] = value;
200
+ }
201
+ break;
202
+ case 'domain_name':
203
+ case 'domainName':
204
+ case 'domain':
205
+ case 'email_domain':
206
+ case 'emailDomain':
207
+ case 'email_domain_name':
208
+ case 'emailDomainName':
209
+ if (isValidDomainName(value)) {
210
+ returnObj[key] = value;
211
+ }
212
+ break;
213
+ case 'expires_at':
214
+ case 'expiresAt':
215
+ if (isValidTimestampzString(value) || isValidTimestampString(value)) {
216
+ returnObj[key] = value;
217
+ }
218
+ break;
219
+ case 'active':
220
+ if (isBoolValue(value)) {
221
+ returnObj[key] = value;
222
+ }
223
+ break;
222
224
  }
223
- break;
224
225
  }
225
- }
226
226
 
227
- return returnObj;
227
+ return returnObj;
228
228
  }
229
229
 
230
230
  module.exports = {
231
- validateProperties,
231
+ validateProperties,
232
232
  };