mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
Merge pull request #111 from Permissionless-Software-Foundation/dh-pagination
feat(NFTs): Added pagination controls for NFTs
This commit is contained in:
@@ -267,7 +267,7 @@ class OfferUseCases {
|
||||
}
|
||||
}
|
||||
|
||||
async listNftOffers (page = 0, nsfw = false) {
|
||||
/* async listNftOffers (page = 0, nsfw = false) {
|
||||
try {
|
||||
const data = await this.OfferModel.find({
|
||||
displayCategory: { $ne: 'fungible' },
|
||||
@@ -287,6 +287,42 @@ class OfferUseCases {
|
||||
console.error('Error in use-cases/offer/listNftOffers()')
|
||||
throw error
|
||||
}
|
||||
} */
|
||||
|
||||
async listNftOffers (page = 0, nsfw = false) {
|
||||
try {
|
||||
const query = {
|
||||
displayCategory: { $ne: 'fungible' },
|
||||
nsfw
|
||||
}
|
||||
// Total query offers
|
||||
const totalOffers = await this.OfferModel.countDocuments(query)
|
||||
// Total pages
|
||||
const totalPages = Math.ceil(totalOffers / NFT_ENTRIES_PER_PAGE)
|
||||
|
||||
const data = await this.OfferModel.find(query)
|
||||
// Sort entries so newest entries show first.
|
||||
.sort('-timestamp')
|
||||
// Skip to the start of the selected page.
|
||||
.skip(page * NFT_ENTRIES_PER_PAGE)
|
||||
// Only return 20 results.
|
||||
.limit(NFT_ENTRIES_PER_PAGE)
|
||||
|
||||
// console.log('listNftOffers() returning this data: ', data)
|
||||
|
||||
return {
|
||||
data,
|
||||
pagination: {
|
||||
currentPage: page,
|
||||
totalPages,
|
||||
totalOffers,
|
||||
pageSize: NFT_ENTRIES_PER_PAGE
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in use-cases/offer/listNftOffers()')
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async listFungibleOffers (page = 0) {
|
||||
|
||||
@@ -149,7 +149,7 @@ const localdb = {
|
||||
static findById () {}
|
||||
static find () {}
|
||||
static findOne () {}
|
||||
|
||||
static countDocuments(){}
|
||||
async save () {
|
||||
return {}
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ describe('#offer-use-case', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('should list orders', async () => {
|
||||
it('should list offers', async () => {
|
||||
const queryMock = {
|
||||
sort () {
|
||||
return this
|
||||
@@ -414,7 +414,11 @@ describe('#offer-use-case', () => {
|
||||
sandbox.stub(uut.OfferModel, 'find').returns(queryMock)
|
||||
|
||||
const result = await uut.listNftOffers(1, true)
|
||||
assert.isArray(result)
|
||||
assert.isObject(result)
|
||||
assert.property(result, 'data')
|
||||
assert.property(result, 'pagination')
|
||||
assert.isArray(result.data)
|
||||
assert.isObject(result.pagination)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user