diff --git a/src/adapters/localdb/models/offer.js b/src/adapters/localdb/models/offer.js index b5eed7b..1acc475 100644 --- a/src/adapters/localdb/models/offer.js +++ b/src/adapters/localdb/models/offer.js @@ -23,7 +23,8 @@ const Offer = new mongoose.Schema({ sigMsg: { type: String }, // Utility data - timestamp: { type: String }, + timestamp: { type: Number }, + globalTimestamp: { type: String }, localTimestamp: { type: String }, // SWaP Protocol Properties diff --git a/src/entities/offer.js b/src/entities/offer.js index 2fc502c..8b57b97 100644 --- a/src/entities/offer.js +++ b/src/entities/offer.js @@ -70,6 +70,10 @@ class OfferEntity { throw new Error("Property 'ticker' must be a string.") } + // Convert the timestamp to a number. + let timestamp = new Date(offerData.timestamp) + timestamp = timestamp.getTime() + const validatedOfferData = { messageType, messageClass, @@ -80,7 +84,8 @@ class OfferEntity { numTokens, utxoTxid, utxoVout, - timestamp: offerData.timestamp, + timestamp, + globaltimestamp: offerData.timestamp, localTimestamp: offerData.localTimeStamp, txid: offerData.txid, p2wdbHash: offerData.hash, diff --git a/src/use-cases/offer/index.js b/src/use-cases/offer/index.js index c848d62..bbdf1a5 100644 --- a/src/use-cases/offer/index.js +++ b/src/use-cases/offer/index.js @@ -93,7 +93,7 @@ class OfferUseCases { async listOffers () { try { - return this.OfferModel.find({}) + return this.OfferModel.find({}).sort('-timestamp') } catch (error) { console.error('Error in use-cases/offer/listOffers()') throw error