Skip to content

Commit

Permalink
improve dates validation for setting nodes operational status
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeshanakram3 committed Mar 27, 2024
1 parent 3ed2fdd commit 692abf5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/mappings/storage/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ export function processNodeOperationalStatusMetadata(
// For status type NoServiceFrom
else if (meta.noServiceFrom) {
const from = parseDateStr(meta.noServiceFrom.from)
if (!from) {

// Date must be in the future
if (!from || from < new Date()) {
invalidMetadata(
NodeOperationalStatusNoServiceFromMetadata,
`Invalid date format for "noServiceFrom"`,
`Invalid date for "noServiceFrom"`,
{ decodedMessage: meta.noServiceFrom }
)
return currentStatus
Expand All @@ -170,10 +172,12 @@ export function processNodeOperationalStatusMetadata(
else if (meta.noServiceUntil) {
const from = meta.noServiceUntil.from ? parseDateStr(meta.noServiceUntil.from) : new Date()
const until = parseDateStr(meta.noServiceUntil.until)
if (!from || !until) {

// Dates must be in the future and "until" must be after "from"
if (!from || !until || from < new Date() || from > until) {
invalidMetadata(
NodeOperationalStatusNoServiceUntilMetadata,
`Invalid date format for "noServiceUntil"`,
`Invalid date/s for "noServiceUntil"`,
{ decodedMessage: meta.noServiceUntil }
)
return currentStatus
Expand Down

0 comments on commit 692abf5

Please sign in to comment.