Skip to content

Commit 48fab33

Browse files
committed
review
1 parent ecc223b commit 48fab33

File tree

7 files changed

+13
-14
lines changed

7 files changed

+13
-14
lines changed

Models/Caller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const CallerSchema = new mongoose.Schema({
3636
},
3737
createdAt: {
3838
type: Date,
39-
default: new Date()
39+
default: Date.now
4040
}
4141
});
4242

Models/Campaign.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const CampaignSchema = new mongoose.Schema({
2626
},
2727
createdAt: {
2828
type: Date,
29-
default: Date.now()
29+
default: Date.now
3030
},
3131
password: {
3232
type: String,

Models/Client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ const ClientSchema = new mongoose.Schema({
4141
},
4242
firstIntegration: {
4343
type: Date,
44-
default: Date.now()
44+
default: Date.now
4545
},
4646
integrationReason: {
4747
type: String,
4848
default: 'unknown'
4949
},
5050
createdAt: {
5151
type: Date,
52-
default: Date.now()
52+
default: Date.now
5353
}
5454
});
5555

router/admin/client/createClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export default async function createClient(req: Request<any>, res: Response<any>
160160
}
161161
} else {
162162
client = new Client({
163-
name: sanitizeString(req.body.name) ?? 'unknown',
163+
name: sanitizeString(req.body.name || 'unknown'),
164164
phone: phone,
165165
firstname: sanitizeString(req.body.firstName ?? ''),
166166
institution: sanitizeString(req.body.institution ?? ''),

router/admin/client/createClients.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default async function createClients(req: Request<any>, res: Response<any
6363
(usr.firstname === undefined || typeof usr.firstname === 'string') &&
6464
(usr.institution === undefined || typeof usr.institution === 'string') &&
6565
(usr.priority === undefined || typeof usr.priority === 'string') &&
66-
(usr.firstIntegration === undefined || !isNaN(parseInt(usr.firstIntegration))) &&
66+
(usr.firstIntegration === undefined || !isNaN(new Date(usr.firstIntegration).getTime())) &&
6767
(usr.integrationReason === undefined || typeof usr.integrationReason === 'string')
6868
);
6969
});
@@ -147,8 +147,7 @@ export default async function createClients(req: Request<any>, res: Response<any
147147
const date = new Date(usr.firstIntegration || '');
148148
return isNaN(date.getTime()) ? Date.now() : date.getTime();
149149
})(),
150-
integrationReason:
151-
sanitizeString(usr.integrationReason || '') ?? sanitizeString(req.body.defaultReason)
150+
integrationReason: sanitizeString(usr.integrationReason || req.body.defaultReason || '')
152151
},
153152
{ $push: { campaigns: campaign._id } }
154153
);
@@ -165,13 +164,12 @@ export default async function createClients(req: Request<any>, res: Response<any
165164
const date = new Date(usr.firstIntegration || '');
166165
return isNaN(date.getTime()) ? Date.now() : date.getTime();
167166
})(),
168-
integrationReason:
169-
sanitizeString(usr.integrationReason || '') ?? sanitizeString(req.body.defaultReason)
167+
integrationReason: sanitizeString(usr.integrationReason || req.body.defaultReason || '')
170168
}
171169
);
172170
}
173171
} catch (error: any) {
174-
errors.push([usr.name || '' + ' ' + usr.firstname || '', phone, error.message]);
172+
errors.push([(usr.name || '') + ' ' + (usr.firstname || ''), phone, error.message]);
175173
}
176174
}
177175
);

router/caller/getPhoneNumber.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export default async function getPhoneNumber(req: Request<any>, res: Response<an
114114
if (!client) {
115115
res.status(404).send({ message: 'Client not found', OK: false });
116116
log(`[${req.body.phone}, ${ip}] Client not found`, 'WARNING', __filename);
117+
return;
117118
}
118119

119120
res.status(200).send({

tools/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ function cleanStatus(status: 'In progress' | 'to recall' | 'Done' | 'deleted' |
111111
* @param str - The string to be sanitized.
112112
* @returns The sanitized string with leading and trailing whitespace removed.
113113
*/
114-
function sanitizeString(str: string) {
115-
str = str.replace(/[{,},$]/gm, '');
114+
function sanitizeString(str?: string) {
115+
str = str?.replace(/[{,},$]/gm, '') ?? '';
116116
return str.trim();
117117
}
118118

@@ -205,7 +205,7 @@ function checkParameters(
205205
// });
206206
// log(`[${ip}] ` + errorText, 'WARNING', orgin);
207207
// return false;
208-
} else if (parameter[1] == 'Date' && !isNaN(new Date(body[parameter[0]]).getTime())) {
208+
} else if (parameter[1] == 'Date' && isNaN(new Date(body[parameter[0]]).getTime())) {
209209
res.status(400).send({
210210
message: errorText,
211211
OK: false

0 commit comments

Comments
 (0)