fix(order): Adding 'orderStatus' to Order model

This commit is contained in:
Chris Troutner
2022-03-09 14:25:37 -08:00
parent fb00c1bc86
commit 5fc26dcc7c
3 changed files with 15 additions and 13 deletions
+2 -1
View File
@@ -17,7 +17,8 @@ const Order = new mongoose.Schema({
timestamp: { type: String },
localTimestamp: { type: String },
p2wdbTxid: { type: String },
p2wdbHash: { type: String }
p2wdbHash: { type: String },
orderStatus: { type: String }
})
module.exports = mongoose.model('order', Order)
+10 -12
View File
@@ -4,6 +4,10 @@
It's destroyed when the UTXO described in the Signal has been detected as spent.
*/
class OrderEntity {
constructor () {
this.orderStatus = ['posted', 'taken', 'completed']
}
validate (orderData = {}) {
// Throw an error if input object does not have a data property
if (!orderData.data) {
@@ -12,17 +16,7 @@ class OrderEntity {
)
}
const {
messageType,
messageClass,
tokenId,
buyOrSell,
rateInSats,
minSatsToExchange,
numTokens,
utxoTxid,
utxoVout
} = orderData.data
const {messageType, messageClass, tokenId, buyOrSell, rateInSats, minSatsToExchange, numTokens, utxoTxid, utxoVout, orderStatus} = orderData.data
// Input Validation
if (!messageType || typeof messageType !== 'number') {
@@ -52,6 +46,9 @@ class OrderEntity {
if (typeof utxoVout !== 'number') {
throw new Error("Property 'utxoVout' must be an integer number.")
}
if (orderStatus && !this.orderStatus.includes(orderStatus)) {
throw new Error("Property 'orderStatus' must be a valid string")
}
const validatedOrderData = {
messageType,
@@ -66,7 +63,8 @@ class OrderEntity {
timestamp: orderData.timestamp,
localTimestamp: orderData.localTimeStamp,
txid: orderData.txid,
p2wdbHash: orderData.hash
p2wdbHash: orderData.hash,
orderStatus: orderStatus || this.orderStatus[0]
}
return validatedOrderData
+3
View File
@@ -43,6 +43,9 @@ class OrderUseCases {
console.log('utxoStatus: ', utxoStatus)
if (utxoStatus === null) return false
// A new order gets a status of 'posted'
orderObj.data.orderStatus = 'posted'
const orderEntity = this.orderEntity.validate(orderObj)
console.log('orderEntity: ', orderEntity)