feat(offer/list): Returning Offers sorted by newest first

This commit is contained in:
Chris Troutner
2022-04-01 19:05:31 -07:00
parent 6e7ab40dea
commit 9aae6da4a7
3 changed files with 9 additions and 3 deletions
+2 -1
View File
@@ -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
+6 -1
View File
@@ -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,
+1 -1
View File
@@ -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