diff --git a/apps/drec-api/src/pods/reads/reads.controller.ts b/apps/drec-api/src/pods/reads/reads.controller.ts index c0a1ff653..875c3e56c 100644 --- a/apps/drec-api/src/pods/reads/reads.controller.ts +++ b/apps/drec-api/src/pods/reads/reads.controller.ts @@ -459,74 +459,79 @@ export class ReadsController extends BaseReadsController { for (const key in ele) { if (key === 'starttimestamp' || key === 'endtimestamp') { if (ele[key]) { - let dateString = ele[key].toString(); const dateTimeRegex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.{0,1}\d{0,3}$/; - if (dateString.includes('.')) { + if (ele[key].toString().includes('.')) { if ( Number.isNaN( parseFloat( - dateString.substring( - dateString.indexOf('.'), - dateString.length, - ), + ele[key] + .toString() + .substring( + ele[key].toString().indexOf('.'), + ele[key].toString().length, + ), ), ) ) { this.logger.error( - `Invalid date sent ${dateString}` + + `Invalid date sent ${ele[key]}` + ` please sent valid date, format for dates is YYYY-MM-DD hh:mm:ss example 2020-02-19 19:20:55 or to include milliseconds add dot and upto 3 digits after seconds example 2020-02-19 19:20:55.2 or 2020-02-19 19:20:54.333`, ); throw new ConflictException({ success: false, message: - `Invalid date sent ${dateString}` + + `Invalid date sent ${ele[key]}` + ` please sent valid date, format for dates is YYYY-MM-DD hh:mm:ss example 2020-02-19 19:20:55 or to include milliseconds add dot and upto 3 digits after seconds example 2020-02-19 19:20:55.2 or 2020-02-19 19:20:54.333`, }); } } - if (!dateTimeRegex.test(dateString)) { + if (!dateTimeRegex.test(ele[key].toString())) { dateInvalid = true; this.logger.error( - `Invalid date sent ${dateString}` + + `Invalid date sent ${ele[key]}` + ` please sent valid date, format for dates is YYYY-MM-DD hh:mm:ss example 2020-02-19 19:20:55 or to include milliseconds add dot and upto 3 digits after seconds example 2020-02-19 19:20:55.2 or 2020-02-19 19:20:54.333`, ); throw new ConflictException({ success: false, message: - `Invalid date sent ${dateString}` + + `Invalid date sent ${ele[key]}` + ` please sent valid date, format for dates is YYYY-MM-DD hh:mm:ss example 2020-02-19 19:20:55 or to include milliseconds add dot and upto 3 digits after seconds example 2020-02-19 19:20:55.2 or 2020-02-19 19:20:54.333`, }); } else { const dateTime = momentTimeZone.tz( - dateString, + ele[key], measurements.timezone, ); if (!dateTime.isValid()) { dateInvalid = true; - this.logger.error(`Invalid date sent ${dateString}`); + this.logger.error(`Invalid date sent ${ele[key]}`); throw new ConflictException({ success: false, - message: `Invalid date sent ${dateString}`, + message: `Invalid date sent ${ele[key]}`, }); } else { let milliSeondsToAddSentInRequest = ''; if ( - dateString.includes('.') && + ele[key].toString().includes('.') && !isNaN( parseInt( - dateString.substring( - dateString.indexOf('.'), - dateString.length, - ), + ele[key] + .toString() + .substring( + ele[key].toString().indexOf('.'), + ele[key].toString().length, + ), ), ) ) { - milliSeondsToAddSentInRequest = dateString.substring( - dateString.indexOf('.'), - dateString.length, - ); + milliSeondsToAddSentInRequest = ele[key] + .toString() + .substring( + ele[key].toString().indexOf('.'), + ele[key].toString().length, + ); } let utcString: string = dateTime.clone().utc().format(); @@ -539,7 +544,7 @@ export class ReadsController extends BaseReadsController { utcString = utcString.substring(0, utcString.length - 1) + '.000Z'; } - dateString = utcString; + ele[key] = new Date(utcString); } } } @@ -1029,74 +1034,79 @@ export class ReadsController extends BaseReadsController { for (const key in ele) { if (key === 'starttimestamp' || key === 'endtimestamp') { if (ele[key]) { - let dateString = ele[key].toString(); const dateTimeRegex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.{0,1}\d{0,3}$/; - if (dateString.includes('.')) { + if (ele[key].toString().includes('.')) { if ( Number.isNaN( parseFloat( - dateString.substring( - dateString.indexOf('.'), - dateString.length, - ), + ele[key] + .toString() + .substring( + ele[key].toString().indexOf('.'), + ele[key].toString().length, + ), ), ) ) { this.logger.error( - `Invalid date sent ${dateString}` + + `Invalid date sent ${ele[key]}` + ` please sent valid date, format for dates is YYYY-MM-DD hh:mm:ss example 2020-02-19 19:20:55 or to include milliseconds add dot and upto 3 digits after seconds example 2020-02-19 19:20:55.2 or 2020-02-19 19:20:54.333`, ); throw new ConflictException({ success: false, message: - `Invalid date sent ${dateString}` + + `Invalid date sent ${ele[key]}` + ` please sent valid date, format for dates is YYYY-MM-DD hh:mm:ss example 2020-02-19 19:20:55 or to include milliseconds add dot and upto 3 digits after seconds example 2020-02-19 19:20:55.2 or 2020-02-19 19:20:54.333`, }); } } - if (!dateTimeRegex.test(dateString)) { + if (!dateTimeRegex.test(ele[key].toString())) { dateInvalid = true; this.logger.error( - `Invalid date sent ${dateString}` + + `Invalid date sent ${ele[key]}` + ` please sent valid date, format for dates is YYYY-MM-DD hh:mm:ss example 2020-02-19 19:20:55 or to include milliseconds add dot and upto 3 digits after seconds example 2020-02-19 19:20:55.2 or 2020-02-19 19:20:54.333`, ); throw new ConflictException({ success: false, message: - `Invalid date sent ${dateString}` + + `Invalid date sent ${ele[key]}` + ` please sent valid date, format for dates is YYYY-MM-DD hh:mm:ss example 2020-02-19 19:20:55 or to include milliseconds add dot and upto 3 digits after seconds example 2020-02-19 19:20:55.2 or 2020-02-19 19:20:54.333`, }); } else { const dateTime = momentTimeZone.tz( - dateString, + ele[key], measurements.timezone, ); if (!dateTime.isValid()) { - this.logger.error(`Invalid date sent ${dateString}`); + this.logger.error(`Invalid date sent ${ele[key]}`); dateInvalid = true; throw new ConflictException({ success: false, - message: `Invalid date sent ${dateString}`, + message: `Invalid date sent ${ele[key]}`, }); } else { let milliSeondsToAddSentInRequest = ''; if ( - dateString.includes('.') && + ele[key].toString().includes('.') && !isNaN( parseInt( - dateString.substring( - dateString.indexOf('.'), - dateString.length, - ), + ele[key] + .toString() + .substring( + ele[key].toString().indexOf('.'), + ele[key].toString().length, + ), ), ) ) { - milliSeondsToAddSentInRequest = dateString.substring( - dateString.indexOf('.'), - dateString.length, - ); + milliSeondsToAddSentInRequest = ele[key] + .toString() + .substring( + ele[key].toString().indexOf('.'), + ele[key].toString().length, + ); } let utcString: string = dateTime.clone().utc().format(); @@ -1109,7 +1119,7 @@ export class ReadsController extends BaseReadsController { utcString = utcString.substring(0, utcString.length - 1) + '.000Z'; } - dateString = utcString; + ele[key] = new Date(utcString); } } } diff --git a/version b/version index 297b2ecb4..3954434a4 100755 --- a/version +++ b/version @@ -1 +1 @@ -0.0.134 +0.0.135