feat(userdata): Store user data on the database

This commit is contained in:
Daniel Gonzalez
2025-10-20 18:37:54 -04:00
parent 8e3ee3a0fb
commit fed98d51be
3 changed files with 28 additions and 6 deletions
+1
View File
@@ -47,6 +47,7 @@ const Offer = new mongoose.Schema({
tokenIconUrl: { type: String, default: null },
tokenCategories: { type: Array, default: [] },
tokenTags: { type: Array, default: [] },
userDataStr: { type: String }, // Token user data
lastUpdatedTokenData: { type: String, default: null } // ISO timestamp of the last time token data was updated.
})
+11 -5
View File
@@ -141,12 +141,18 @@ class OfferUseCases {
// Get the mutable data from the cid if it exists.
if (mutableDataCid && typeof mutableDataCid === 'string') {
const mutableData = await this.retryQueue.addToQueue(this.adapters.wallet.cid2json, mutableDataCid)
// console.log('mutableData: ', mutableData)
console.log('mutableData: ', mutableData)
if (mutableData) {
offerEntity.tokenIconUrl = mutableData.tokenIcon
offerEntity.tokenCategories = mutableData.category
offerEntity.tokenTags = mutableData.tags
offerEntity.lastUpdatedTokenData = new Date().getTime()
try {
offerEntity.tokenIconUrl = mutableData.tokenIcon
offerEntity.tokenCategories = mutableData.category
offerEntity.tokenTags = mutableData.tags
offerEntity.lastUpdatedTokenData = new Date().getTime()
offerEntity.userDataStr = JSON.stringify(mutableData.userData)
} catch (error) {
// skip error
}
}
}
+16 -1
View File
@@ -112,7 +112,22 @@ describe('#offer-use-case', () => {
const tokenDataMock = mockData.nftTokenData01
const offerObj = mockData.offerMockData
const mutableDataMock = mockData.mutableDataMock
console.log('mutableDataMock: ', mutableDataMock)
// Mock dependencies
// sandbox.stub(uut.adapters.wallet.bchWallet, 'utxoIsValid').resolves(false)
sandbox.stub(uut, 'findOfferByTxid').throws(new Error('offer not found'))
sandbox.stub(uut.retryQueue, 'addToQueue')
.onCall(0).resolves({}) // Utxo Status call
.onCall(1).resolves(tokenDataMock) // Token Data call
.onCall(2).resolves(mutableDataMock)
const result = await uut.createOffer(offerObj)
assert.isTrue(result)
})
it('should skip userData stringify error', async () => {
const tokenDataMock = mockData.nftTokenData01
const offerObj = mockData.offerMockData
const mutableDataMock = mockData.mutableDataMock
mutableDataMock.userData = { n: 10n }
// Mock dependencies
// sandbox.stub(uut.adapters.wallet.bchWallet, 'utxoIsValid').resolves(false)
sandbox.stub(uut, 'findOfferByTxid').throws(new Error('offer not found'))