ingeni-validation 1.1.10 → 1.1.11
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.
- package/ingeni-validation.js +43 -9
- package/package.json +1 -1
package/ingeni-validation.js
CHANGED
|
@@ -311,19 +311,23 @@ async function isValidDate(value, format) {
|
|
|
311
311
|
//Stop details Validation "stop_details":[{"30":["Baripada","13:00","13:01","21.9319,86.7465"]}]
|
|
312
312
|
|
|
313
313
|
async function isValidStopDetails(stop_details){
|
|
314
|
+
console.log("api stop details"+stop_details);
|
|
314
315
|
|
|
315
316
|
if (!Array.isArray(stop_details) || stop_details.length === 0){
|
|
316
317
|
return false;
|
|
317
318
|
}
|
|
318
319
|
|
|
319
320
|
const timeRegex = /^([01][0-9]|2[0-3]):([0-5][0-9])$/;
|
|
321
|
+
const latlongRegex = /^-?\d+(\.\d+)?,-?\d+(\.\d+)?$/;
|
|
320
322
|
|
|
321
323
|
const toMinutes = (t)=>{
|
|
322
324
|
const [h,m] = t.split(":").map(Number);
|
|
323
325
|
return h*60 + m;
|
|
324
326
|
};
|
|
325
327
|
|
|
326
|
-
|
|
328
|
+
let usedIds = new Set();
|
|
329
|
+
let expectedStopId = 1;
|
|
330
|
+
let previousArrival = -1;
|
|
327
331
|
|
|
328
332
|
for (let stop of stop_details){
|
|
329
333
|
|
|
@@ -339,11 +343,25 @@ async function isValidStopDetails(stop_details){
|
|
|
339
343
|
|
|
340
344
|
const stop_id = keys[0];
|
|
341
345
|
|
|
342
|
-
// stop id
|
|
346
|
+
// stop id numeric
|
|
343
347
|
if (!/^\d+$/.test(stop_id)){
|
|
344
348
|
return false;
|
|
345
349
|
}
|
|
346
350
|
|
|
351
|
+
const stopIdNum = Number(stop_id);
|
|
352
|
+
|
|
353
|
+
// 1️⃣ Duplicate stop ID check
|
|
354
|
+
if (usedIds.has(stopIdNum)){
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
usedIds.add(stopIdNum);
|
|
358
|
+
|
|
359
|
+
// 2️⃣ Sequential stop check
|
|
360
|
+
if (stopIdNum !== expectedStopId){
|
|
361
|
+
return false;
|
|
362
|
+
}
|
|
363
|
+
expectedStopId++;
|
|
364
|
+
|
|
347
365
|
const values = stop[stop_id];
|
|
348
366
|
|
|
349
367
|
if (!Array.isArray(values) || values.length !== 4){
|
|
@@ -352,26 +370,42 @@ async function isValidStopDetails(stop_details){
|
|
|
352
370
|
|
|
353
371
|
let [stop_name, arrival_time, departure_time, latlong] = values;
|
|
354
372
|
|
|
355
|
-
|
|
356
|
-
|
|
373
|
+
if (typeof stop_name !== "string" ||
|
|
374
|
+
typeof arrival_time !== "string" ||
|
|
375
|
+
typeof departure_time !== "string" ||
|
|
376
|
+
typeof latlong !== "string"){
|
|
357
377
|
return false;
|
|
358
378
|
}
|
|
359
379
|
|
|
360
|
-
|
|
380
|
+
stop_name = stop_name.trim();
|
|
381
|
+
arrival_time = arrival_time.trim();
|
|
382
|
+
departure_time = departure_time.trim();
|
|
383
|
+
latlong = latlong.trim();
|
|
384
|
+
|
|
385
|
+
if (stop_name.length === 0) return false;
|
|
386
|
+
|
|
361
387
|
if (!timeRegex.test(arrival_time) || !timeRegex.test(departure_time)){
|
|
362
388
|
return false;
|
|
363
389
|
}
|
|
364
390
|
|
|
365
|
-
|
|
366
|
-
|
|
391
|
+
const arrivalMin = toMinutes(arrival_time);
|
|
392
|
+
const departMin = toMinutes(departure_time);
|
|
393
|
+
|
|
394
|
+
// arrival <= departure
|
|
395
|
+
if (arrivalMin > departMin){
|
|
367
396
|
return false;
|
|
368
397
|
}
|
|
369
398
|
|
|
370
|
-
//
|
|
371
|
-
if (
|
|
399
|
+
// 3️⃣ Next stop must be after previous stop
|
|
400
|
+
if (arrivalMin <= previousArrival){
|
|
372
401
|
return false;
|
|
373
402
|
}
|
|
374
403
|
|
|
404
|
+
previousArrival = arrivalMin;
|
|
405
|
+
|
|
406
|
+
// mandatory coordinates
|
|
407
|
+
if (latlong.length === 0) return false;
|
|
408
|
+
|
|
375
409
|
if (!latlongRegex.test(latlong)){
|
|
376
410
|
return false;
|
|
377
411
|
}
|