mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
fix(order): Adding 'orderStatus' to Order model
This commit is contained in:
@@ -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
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user