diff --git a/backend/graphql/resolvers/nft.js b/backend/graphql/resolvers/nft.js index f234e11..77e034b 100644 --- a/backend/graphql/resolvers/nft.js +++ b/backend/graphql/resolvers/nft.js @@ -18,6 +18,7 @@ module.exports = { throw err; } }, + singleNft: async args => { try { const nfts = await Nft.find(); @@ -122,6 +123,7 @@ module.exports = { try { const nfts = await Nft.find() + const likes = await LikeNft.find({ liker_collection_address: args.collectionAddress, liker_token_id: args.tokenId @@ -131,20 +133,87 @@ module.exports = { disliker_token_id: args.tokenId }) + const us_like = await LikeNft.find({ + liked_collection_address: args.collectionAddress, + liked_token_id: args.tokenId + }) + const filtered = nfts + .filter(not_own) + .filter(n => { + const c = likes.find(l => { + return l.liked_collection_address == n.collectionAddress + && l.liked_token_id == n.tokenId + }) - // console.log(likes) - + const d = dislikes.find(l=>{ + return l.disliked_collection_address == n.collectionAddress + && l.disliked_token_id == n.tokenId + }) - return nfts - .filter(not_own) - .filter(n => { // TODO - return !likes.concat(dislikes).find(l => l.collectionAddress == n.collectionAddress && l.tokenId == n.tokenId) + return !c && !d; }) - .map(transformNft) + + const liked = [] + + const other = [] + + filtered.forEach(n=>{ + + if (us_like.find(l=>l.liker_collection_address==n.collectionAddress + &&l.liker_token_id==n.tokenId)) { + liked.push(n) + } else { + other.push(n) + } + }) + + const all = liked.concat(other) + + return all.map(transformNft) + } catch (err) { throw err; } + }, + + findMatch: async args => { + + const is_match = my=>yours=> { + return my.liked_token_id == yours.liker_token_id + && my.liked_collection_address == yours.liked_collection_address + } + + try { + + const we_like = await LikeNft.find({ + liker_collection_address: args.collectionAddress, + liker_token_id: args.tokenId + }) + const us_like = await LikeNft.find({ + liked_collection_address: args.collectionAddress, + liked_token_id: args.tokenId + }) + + const match = we_like.find(we=>{ + return us_like.find(is_match(we)); + }) + + if (!match) return ['','','',''] + + console.log('MATCH'); + console.log(match); + + return [ + match.liker_collection_address, + match.liker_token_id, + match.liked_collection_address, + match.liked_token_id + ] + + } catch (err) { + throw err; + } } } \ No newline at end of file diff --git a/backend/graphql/schema/index.js b/backend/graphql/schema/index.js index b0132f6..72706ff 100644 --- a/backend/graphql/schema/index.js +++ b/backend/graphql/schema/index.js @@ -82,6 +82,7 @@ type RootQuery { nfts: [Nft!] singleNft(nftOwnId: ID!): Nft! showLikeNfts(nftOwnId: ID!): [Nft!] + findMatch(collectionAddress: String!, tokenId: String!): [String!] showUnseenNfts(user: String!, collectionAddress: String!, tokenId: String!): [Nft!] } diff --git a/frontend/src/components/Slider.vue b/frontend/src/components/Slider.vue index b2cd1e6..9449516 100644 --- a/frontend/src/components/Slider.vue +++ b/frontend/src/components/Slider.vue @@ -59,6 +59,8 @@ export default { async handleDecision(decision) { if(decision === "like") { await this.sendLike(); + + await this.fetchMatch(); } else { await this.sendDislike(); @@ -85,6 +87,30 @@ export default { this.queue = this.queue.length > 1 ? this.queue.slice(1) : []; }, + + async fetchMatch() { + + const q= + `query{ + findMatch( + collectionAddress:"${this.user_nft.collectionAddress}", + tokenId: "${this.user_nft.collectionTokenId}" + ) + }` + + const r = await this.sendQuery(q) + + const res = await r.json() + + const m = res.data.findMatch + + if (m && m[0]!='') { + alert('WE HAVE A MATCH') + console.log(m) + } + + }, + async sendLike() { const q = @@ -95,12 +121,14 @@ export default { liked_collection_address: "${this.current.collectionAddress}", liked_token_id: "${this.current.tokenId}" }) { - collectionName - picUrl + liker_collection_address + liker_token_id + liked_collection_address + liked_token_id } }` - // console.log(q) + console.log(q) const r = await this.sendQuery(q) // console.log(r) @@ -119,8 +147,10 @@ export default { disliked_collection_address: "${this.current.collectionAddress}", disliked_token_id: "${this.current.tokenId}" }) { - collectionName - picUrl + disliker_collection_address + disliker_token_id + disliked_collection_address + disliked_token_id } }`