Skip to content

Commit

Permalink
Adds brand to pools overview
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpolman committed May 27, 2024
1 parent 3654243 commit 7dc3814
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion apps/api/src/app/services/PoolService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
QuestDaily,
CouponCode,
WalletDocument,
Brand,
} from '@thxnetwork/api/models';

import AccountProxy from '../proxies/AccountProxy';
Expand Down Expand Up @@ -108,11 +109,22 @@ async function getAllBySub(sub: string): Promise<PoolDocument[]> {
pools = pools.concat(collaborationPools);
}

// Get usernames for pool owners
const subs = pools.map((p) => p.sub);
const accounts = await AccountProxy.find({ subs });

// Add Safes to pools
return await Promise.all(
pools.map(async (pool) => {
const brand = await Brand.findOne({ poolId: pool.id });
const safe = await SafeService.findOneByPool(pool);
return { ...pool.toJSON(), safe };
const participantCount = await Participant.countDocuments({ poolId: pool.id });
const account = accounts.find((a) => a.sub === pool.sub);
const author = account && {
username: account.username,
};

return { ...pool.toJSON(), participantCount, author, brand, safe };
}),
);
}
Expand Down

0 comments on commit 7dc3814

Please sign in to comment.