From 9aae6da4a71aac3cbd2b3285b71f5ad895cdac66 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Fri, 1 Apr 2022 19:05:31 -0700 Subject: [PATCH] feat(offer/list): Returning Offers sorted by newest first --- src/adapters/localdb/models/offer.js | 3 ++- src/entities/offer.js | 7 ++++++- src/use-cases/offer/index.js | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) 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