Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stage Push #364

Merged
merged 7 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading