Use getAll
Firestore technology to improve some code (#612)
This commit is contained in:
parent
90d7f55c6d
commit
7dea9cbfa8
|
@ -41,10 +41,7 @@ export const placebet = newEndpoint({}, async (req, auth) => {
|
|||
log('Inside main transaction.')
|
||||
const contractDoc = firestore.doc(`contracts/${contractId}`)
|
||||
const userDoc = firestore.doc(`users/${auth.uid}`)
|
||||
const [contractSnap, userSnap] = await Promise.all([
|
||||
trans.get(contractDoc),
|
||||
trans.get(userDoc),
|
||||
])
|
||||
const [contractSnap, userSnap] = await trans.getAll(contractDoc, userDoc)
|
||||
if (!contractSnap.exists) throw new APIError(400, 'Contract not found.')
|
||||
if (!userSnap.exists) throw new APIError(400, 'User not found.')
|
||||
log('Loaded user and contract snapshots.')
|
||||
|
|
|
@ -21,11 +21,11 @@ export const sellbet = newEndpoint({}, async (req, auth) => {
|
|||
const contractDoc = firestore.doc(`contracts/${contractId}`)
|
||||
const userDoc = firestore.doc(`users/${auth.uid}`)
|
||||
const betDoc = firestore.doc(`contracts/${contractId}/bets/${betId}`)
|
||||
const [contractSnap, userSnap, betSnap] = await Promise.all([
|
||||
transaction.get(contractDoc),
|
||||
transaction.get(userDoc),
|
||||
transaction.get(betDoc),
|
||||
])
|
||||
const [contractSnap, userSnap, betSnap] = await transaction.getAll(
|
||||
contractDoc,
|
||||
userDoc,
|
||||
betDoc
|
||||
)
|
||||
if (!contractSnap.exists) throw new APIError(400, 'Contract not found.')
|
||||
if (!userSnap.exists) throw new APIError(400, 'User not found.')
|
||||
if (!betSnap.exists) throw new APIError(400, 'Bet not found.')
|
||||
|
|
|
@ -24,9 +24,8 @@ export const sellshares = newEndpoint({}, async (req, auth) => {
|
|||
const contractDoc = firestore.doc(`contracts/${contractId}`)
|
||||
const userDoc = firestore.doc(`users/${auth.uid}`)
|
||||
const betsQ = contractDoc.collection('bets').where('userId', '==', auth.uid)
|
||||
const [contractSnap, userSnap, userBets] = await Promise.all([
|
||||
transaction.get(contractDoc),
|
||||
transaction.get(userDoc),
|
||||
const [[contractSnap, userSnap], userBets] = await Promise.all([
|
||||
transaction.getAll(contractDoc, userDoc),
|
||||
getValues<Bet>(betsQ), // TODO: why is this not in the transaction??
|
||||
])
|
||||
if (!contractSnap.exists) throw new APIError(400, 'Contract not found.')
|
||||
|
|
Loading…
Reference in New Issue
Block a user