Skip to content

Commit

Permalink
getAllKittiesWithSwipeRightsForAddress kitties service method
Browse files Browse the repository at this point in the history
  • Loading branch information
vince0656 committed Nov 28, 2019
1 parent f5fa23d commit 4e649ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
23 changes: 21 additions & 2 deletions src/Firebase/CryptoKitties/KittiesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {db} from '../index';

export default new class KittiesService {
async getAllKittiesForAddress(network, address) {
return await db.collection('kitties')
return db.collection('kitties')
.doc('network')
.collection(network)
.where('owner', '==', address)
Expand All @@ -17,7 +17,7 @@ export default new class KittiesService {
}

async getAllSwipeRightsForKittie(network, kittieId) {
return await db.collection('kitties')
return db.collection('kitties')
.doc('network')
.collection(network)
.doc(kittieId)
Expand All @@ -31,6 +31,25 @@ export default new class KittiesService {
});
}

async getAllKittiesWithSwipeRightsForAddress(network, address) {
return db.collection('kitties')
.doc('network')
.collection(network)
.where('owner', '==', address)
.get()
.then(snapshots => {
if (snapshots.empty) {
return [];
}
return Promise.all(snapshots.docs
.map(doc => doc.id)
.map(async kittieId => ({
kittieId,
swipeRights: await this.getAllSwipeRightsForKittie(network, kittieId)
})));
});
}

async poke(network, pokeId, kittieId, message, from, studId) {
return db.collection('kitties')
.doc('network')
Expand Down
14 changes: 1 addition & 13 deletions src/components/Chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,8 @@
this.kitties.other = await KittiesService.getAllKittiesForAddress('mainnet', this.accounts.other);
},
getUserKitties: async function() {
this.kitties.user = await KittiesService.getAllKittiesForAddress('mainnet', this.accounts.user);
this.getAllSwipeRightsForKittie();
this.kitties.user = await KittiesService.getAllKittiesWithSwipeRightsForAddress('mainnet', this.accounts.user);
},
getAllSwipeRightsForKittie: async function() {
// todo - move this into the Kitties Service
const kittiesWithSwipeRights = await Promise.all(this.kitties.user.map(async kittie =>
({
kittieId: kittie,
swipeRights: await KittiesService.getAllSwipeRightsForKittie('mainnet', kittie)
})
));
this.kitties.user = kittiesWithSwipeRights;
console.log('swipeRightsForAllKitties', kittiesWithSwipeRights);
}
},
async mounted() {
messaging.onMessage((payload) => {
Expand Down

0 comments on commit 4e649ef

Please sign in to comment.