Skip to content

Commit

Permalink
Merge pull request #364 from d-rec/develop
Browse files Browse the repository at this point in the history
Stage Push
  • Loading branch information
Aish1990 authored Jul 17, 2024
2 parents d308e40 + ea41696 commit b6d3e54
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 49 deletions.
106 changes: 58 additions & 48 deletions apps/drec-api/src/pods/reads/reads.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -539,7 +544,7 @@ export class ReadsController extends BaseReadsController {
utcString =
utcString.substring(0, utcString.length - 1) + '.000Z';
}
dateString = utcString;
ele[key] = new Date(utcString);
}
}
}
Expand Down Expand Up @@ -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();

Expand All @@ -1109,7 +1119,7 @@ export class ReadsController extends BaseReadsController {
utcString =
utcString.substring(0, utcString.length - 1) + '.000Z';
}
dateString = utcString;
ele[key] = new Date(utcString);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.134
0.0.135

0 comments on commit b6d3e54

Please sign in to comment.