From cb3c4044118388592d30d9c87e827e657050bf52 Mon Sep 17 00:00:00 2001 From: Felipe Sueto Date: Fri, 12 Nov 2021 15:31:06 -0300 Subject: [PATCH] Add datetime validation to 'created' and 'updated' fields --- CHANGELOG.md | 1 + sdk/balance/balance.js | 3 ++- sdk/boleto/boleto.js | 2 +- sdk/boleto/log/log.js | 2 +- sdk/boletoHolmes/boletoHolmes.js | 5 +++-- sdk/boletoHolmes/log/log.js | 2 +- sdk/boletoPayment/boletoPayment.js | 2 +- sdk/boletoPayment/log/log.js | 3 ++- sdk/brcodePayment/brcodePayment.js | 4 ++-- sdk/brcodePayment/log/log.js | 2 +- sdk/darfPayment/darfPayment.js | 4 ++-- sdk/darfPayment/log/log.js | 2 +- sdk/deposit/deposit.js | 5 +++-- sdk/deposit/log/log.js | 2 +- sdk/event/attempt/attempt.js | 3 ++- sdk/event/event.js | 2 +- sdk/invoice/invoice.js | 4 ++-- sdk/invoice/log/log.js | 2 +- sdk/paymentRequest/paymentRequest.js | 7 ++++--- sdk/taxPayment/log/log.js | 5 +++-- sdk/taxPayment/taxPayment.js | 4 ++-- sdk/transaction/transaction.js | 3 ++- sdk/transfer/log/log.js | 3 ++- sdk/transfer/transfer.js | 4 ++-- sdk/utilityPayment/log/log.js | 5 +++-- sdk/utilityPayment/utilityPayment.js | 2 +- 26 files changed, 47 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb50bc2a..776495a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Given a version number MAJOR.MINOR.PATCH, increment: ### Added - 'transactionIds' property to BoletoPayment and TaxPayment resources - 'fee', 'transactionIds', 'created' and 'updated' properties to DarfPayment resource +- datetime validation to 'created' and 'updated' fields ## [2.9.2] - 2021-11-10 ### Changed diff --git a/sdk/balance/balance.js b/sdk/balance/balance.js index 62273c7c..d46fa0e8 100644 --- a/sdk/balance/balance.js +++ b/sdk/balance/balance.js @@ -1,4 +1,5 @@ const rest = require('../utils/rest.js'); +const check = require('../utils/check.js'); const Resource = require('../utils/resource.js').Resource @@ -23,7 +24,7 @@ class Balance extends Resource { super(id); this.amount = amount; this.currency = currency; - this.updated = updated; + this.updated = check.datetime(updated); } } diff --git a/sdk/boleto/boleto.js b/sdk/boleto/boleto.js index e889d0d7..faacf329 100644 --- a/sdk/boleto/boleto.js +++ b/sdk/boleto/boleto.js @@ -76,7 +76,7 @@ class Boleto extends Resource { this.barCode = barCode; this.status = status; this.transactionIds = transactionIds; - this.created = created; + this.created = check.datetime(created); this.ourNumber = ourNumber; } } diff --git a/sdk/boleto/log/log.js b/sdk/boleto/log/log.js index 47da5f18..28096d37 100644 --- a/sdk/boleto/log/log.js +++ b/sdk/boleto/log/log.js @@ -23,7 +23,7 @@ class Log extends Resource { */ constructor({ created, type, errors, boleto, id }) { super(id); - this.created = check.date(created); + this.created = check.datetime(created); this.type = type; this.errors = errors; this.boleto = boleto; diff --git a/sdk/boletoHolmes/boletoHolmes.js b/sdk/boletoHolmes/boletoHolmes.js index 609e2e16..2f5aacdf 100644 --- a/sdk/boletoHolmes/boletoHolmes.js +++ b/sdk/boletoHolmes/boletoHolmes.js @@ -1,4 +1,5 @@ const rest = require('../utils/rest.js'); +const check = require('../utils/check.js'); const Resource = require('../utils/resource.js').Resource @@ -33,8 +34,8 @@ class BoletoHolmes extends Resource { this.tags = tags; this.result = result; this.status = status; - this.created = created; - this.updated = updated; + this.created = check.datetime(created); + this.updated = check.datetime(updated); } } diff --git a/sdk/boletoHolmes/log/log.js b/sdk/boletoHolmes/log/log.js index 8afb1a47..4bfe2040 100644 --- a/sdk/boletoHolmes/log/log.js +++ b/sdk/boletoHolmes/log/log.js @@ -22,7 +22,7 @@ class Log extends Resource { */ constructor({ created, type, holmes, id }) { super(id); - this.created = check.date(created); + this.created = check.datetime(created); this.type = type; this.holmes = holmes; } diff --git a/sdk/boletoPayment/boletoPayment.js b/sdk/boletoPayment/boletoPayment.js index 6bd11ece..185565a4 100644 --- a/sdk/boletoPayment/boletoPayment.js +++ b/sdk/boletoPayment/boletoPayment.js @@ -45,7 +45,7 @@ class BoletoPayment extends Resource { this.amount = amount; this.transactionIds = transactionIds; this.fee = fee; - this.created = check.date(created); + this.created = check.datetime(created); } } diff --git a/sdk/boletoPayment/log/log.js b/sdk/boletoPayment/log/log.js index 7c8ab553..80559da9 100644 --- a/sdk/boletoPayment/log/log.js +++ b/sdk/boletoPayment/log/log.js @@ -1,4 +1,5 @@ const rest = require('../../utils/rest.js'); +const check = require('../../utils/check.js'); const Resource = require('../../utils/resource.js').Resource @@ -22,7 +23,7 @@ class Log extends Resource { */ constructor({ created, type, errors, payment, id }) { super(id); - this.created = created; + this.created = check.datetime(created); this.type = type; this.errors = errors; this.payment = payment; diff --git a/sdk/brcodePayment/brcodePayment.js b/sdk/brcodePayment/brcodePayment.js index c2e3690d..2bdffecd 100644 --- a/sdk/brcodePayment/brcodePayment.js +++ b/sdk/brcodePayment/brcodePayment.js @@ -47,8 +47,8 @@ class BrcodePayment extends Resource { this.status = status; this.type = type; this.fee = fee; - this.updated = check.date(updated); - this.created = check.date(created); + this.updated = check.datetime(updated); + this.created = check.datetime(created); } } diff --git a/sdk/brcodePayment/log/log.js b/sdk/brcodePayment/log/log.js index 5d3fc816..1618cf8c 100644 --- a/sdk/brcodePayment/log/log.js +++ b/sdk/brcodePayment/log/log.js @@ -23,7 +23,7 @@ class Log extends Resource { */ constructor({ created, type, errors, payment, id }) { super(id); - this.created = check.date(created); + this.created = check.datetime(created); this.type = type; this.errors = errors; this.payment = payment; diff --git a/sdk/darfPayment/darfPayment.js b/sdk/darfPayment/darfPayment.js index 1a74e2eb..6071b749 100644 --- a/sdk/darfPayment/darfPayment.js +++ b/sdk/darfPayment/darfPayment.js @@ -58,8 +58,8 @@ class DarfPayment extends Resource { this.nominalAmount = nominalAmount; this.transactionIds = transactionIds; this.fee = fee; - this.updated = check.date(updated); - this.created = check.date(created); + this.updated = check.datetime(updated); + this.created = check.datetime(created); } } diff --git a/sdk/darfPayment/log/log.js b/sdk/darfPayment/log/log.js index a81323d0..a32f23e6 100644 --- a/sdk/darfPayment/log/log.js +++ b/sdk/darfPayment/log/log.js @@ -23,7 +23,7 @@ class Log extends Resource { */ constructor({ created, type, errors, payment, id }) { super(id); - this.created = check.date(created); + this.created = check.datetime(created); this.type = type; this.errors = errors; this.payment = payment; diff --git a/sdk/deposit/deposit.js b/sdk/deposit/deposit.js index 7efee25b..67cfc831 100644 --- a/sdk/deposit/deposit.js +++ b/sdk/deposit/deposit.js @@ -1,4 +1,5 @@ const rest = require('../utils/rest.js'); +const check = require('../utils/check.js'); const Resource = require('../utils/resource.js').Resource; @@ -43,8 +44,8 @@ class Deposit extends Resource { this.tags = tags; this.fee = fee; this.transactionIds = transactionIds; - this.created = created; - this.updated = updated; + this.created = check.datetime(created); + this.updated = check.datetime(updated); } } diff --git a/sdk/deposit/log/log.js b/sdk/deposit/log/log.js index a88a1ab0..09884cd5 100644 --- a/sdk/deposit/log/log.js +++ b/sdk/deposit/log/log.js @@ -23,7 +23,7 @@ class Log extends Resource { */ constructor({ created, type, errors, boleto, id }) { super(id); - this.created = check.date(created); + this.created = check.datetime(created); this.type = type; this.errors = errors; this.boleto = boleto; diff --git a/sdk/event/attempt/attempt.js b/sdk/event/attempt/attempt.js index ed8c9f46..a94b5eed 100644 --- a/sdk/event/attempt/attempt.js +++ b/sdk/event/attempt/attempt.js @@ -1,4 +1,5 @@ const Resource = require('../../utils/resource.js').Resource; +const check = require('../../utils/check.js'); const rest = require('../../utils/rest.js'); @@ -10,7 +11,7 @@ class Attempt extends Resource { this.message = message; this.webhookId = webhookId; this.eventId = eventId; - this.created = created; + this.created = check.datetime(created); } } diff --git a/sdk/event/event.js b/sdk/event/event.js index 468b5317..15e9e39a 100644 --- a/sdk/event/event.js +++ b/sdk/event/event.js @@ -27,7 +27,7 @@ class Event extends Resource { constructor({created, isDelivered, subscription, log, id, workspaceId} = {}) { super(id); this.log = log; - this.created = created; + this.created = check.datetime(created); this.isDelivered = isDelivered; this.subscription = subscription; this.workspaceId = workspaceId; diff --git a/sdk/invoice/invoice.js b/sdk/invoice/invoice.js index 3cb06c38..cfacb6ef 100644 --- a/sdk/invoice/invoice.js +++ b/sdk/invoice/invoice.js @@ -74,8 +74,8 @@ class Invoice extends Resource { this.brcode = brcode; this.status = status; this.transactionIds = transactionIds; - this.created = check.date(created); - this.updated = check.date(updated); + this.created = check.datetime(created); + this.updated = check.datetime(updated); } } diff --git a/sdk/invoice/log/log.js b/sdk/invoice/log/log.js index cd016e74..5d73d394 100644 --- a/sdk/invoice/log/log.js +++ b/sdk/invoice/log/log.js @@ -23,7 +23,7 @@ class Log extends Resource { */ constructor({ created, type, errors, invoice, id }) { super(id); - this.created = check.date(created); + this.created = check.datetime(created); this.type = type; this.errors = errors; this.invoice = invoice; diff --git a/sdk/paymentRequest/paymentRequest.js b/sdk/paymentRequest/paymentRequest.js index df7e2832..1389bd43 100644 --- a/sdk/paymentRequest/paymentRequest.js +++ b/sdk/paymentRequest/paymentRequest.js @@ -4,12 +4,13 @@ const { Transfer } = require('../transfer/transfer.js'); const { UtilityPayment } = require('../utilityPayment/utilityPayment.js'); const { BrcodePayment } = require('../brcodePayment/brcodePayment.js'); const rest = require('../utils/rest.js'); +const check = require('../utils/check.js'); const Resource = require('../utils/resource.js').Resource class PaymentRequest extends Resource { - /** + /** * PaymentRequest constructor * * A PaymentRequest is an indirect request to access a specific cash-out service @@ -48,8 +49,8 @@ class PaymentRequest extends Resource { this.amount = amount; this.status = status; this.actions = actions; - this.updated = updated; - this.created = created; + this.updated = check.datetime(updated); + this.created = check.datetime(created); let parsePaymentObject = parsePayment(payment, type); this.payment = parsePaymentObject['payment']; this.type = parsePaymentObject['type']; diff --git a/sdk/taxPayment/log/log.js b/sdk/taxPayment/log/log.js index 779f2b86..6f8db779 100644 --- a/sdk/taxPayment/log/log.js +++ b/sdk/taxPayment/log/log.js @@ -1,4 +1,5 @@ const rest = require('../../utils/rest.js'); +const check = require('../../utils/check.js'); const Resource = require('../../utils/resource.js').Resource @@ -19,9 +20,9 @@ class Log extends Resource { * @param created [string]: creation datetime for the log. ex: '2020-03-10 10:30:00.000' * */ - constructor(created, type, errors, payment, id = null) { + constructor({ created, type, errors, payment, id = null }) { super(id); - this.created = created; + this.created = check.datetime(created); this.type = type; this.errors = errors; this.payment = payment; diff --git a/sdk/taxPayment/taxPayment.js b/sdk/taxPayment/taxPayment.js index 3c2f763f..c2352c65 100644 --- a/sdk/taxPayment/taxPayment.js +++ b/sdk/taxPayment/taxPayment.js @@ -48,8 +48,8 @@ class TaxPayment extends Resource { this.status = status; this.type = type; this.transactionIds = transactionIds; - this.updated = updated; - this.created = created; + this.updated = check.datetime(updated); + this.created = check.datetime(created); this.fee = fee; } } diff --git a/sdk/transaction/transaction.js b/sdk/transaction/transaction.js index 59dc83a9..bbb0c27a 100644 --- a/sdk/transaction/transaction.js +++ b/sdk/transaction/transaction.js @@ -1,4 +1,5 @@ const rest = require('../utils/rest.js'); +const check = require('../utils/check.js'); const Resource = require('../utils/resource.js').Resource @@ -44,7 +45,7 @@ class Transaction extends Resource { this.fee = fee; this.source = source; this.balance = balance; - this.created = created; + this.created = check.datetime(created); } } diff --git a/sdk/transfer/log/log.js b/sdk/transfer/log/log.js index 4e438bc9..84dea7a3 100644 --- a/sdk/transfer/log/log.js +++ b/sdk/transfer/log/log.js @@ -1,4 +1,5 @@ const rest = require('../../utils/rest.js'); +const check = require('../../utils/check.js'); const Resource = require('../../utils/resource.js').Resource @@ -21,7 +22,7 @@ class Log extends Resource { */ constructor({ created, type, errors, transfer, id }) { super(id); - this.created = created; + this.created = check.datetime(created); this.type = type; this.errors = errors; this.transfer = transfer; diff --git a/sdk/transfer/transfer.js b/sdk/transfer/transfer.js index 20c51e65..fd58c072 100644 --- a/sdk/transfer/transfer.js +++ b/sdk/transfer/transfer.js @@ -54,8 +54,8 @@ class Transfer extends Resource { this.tags = tags; this.fee = fee; this.status = status; - this.created = created; - this.updated = updated; + this.created = check.datetime(created); + this.updated = check.datetime(updated); this.transactionIds = transactionIds; } } diff --git a/sdk/utilityPayment/log/log.js b/sdk/utilityPayment/log/log.js index e8584d7b..57a250a7 100644 --- a/sdk/utilityPayment/log/log.js +++ b/sdk/utilityPayment/log/log.js @@ -1,4 +1,5 @@ const rest = require('../../utils/rest.js'); +const check = require('../../utils/check.js'); const Resource = require('../../utils/resource.js').Resource @@ -19,9 +20,9 @@ class Log extends Resource { * @param created [string]: creation datetime for the log. ex: '2020-03-10 10:30:00.000' * */ - constructor(created, type, errors, payment, id = null) { + constructor({ created, type, errors, payment, id = null }) { super(id); - this.created = created; + this.created = check.datetime(created); this.type = type; this.errors = errors; this.payment = payment; diff --git a/sdk/utilityPayment/utilityPayment.js b/sdk/utilityPayment/utilityPayment.js index 486aac6d..9f5b7d14 100644 --- a/sdk/utilityPayment/utilityPayment.js +++ b/sdk/utilityPayment/utilityPayment.js @@ -44,7 +44,7 @@ class UtilityPayment extends Resource { this.tags = tags; this.amount = amount; this.status = status; - this.created = created; + this.created = check.datetime(created); this.fee = fee; } }