2021-12-11 00:06:17 +00:00
|
|
|
import * as admin from 'firebase-admin'
|
|
|
|
|
2022-01-10 21:07:57 +00:00
|
|
|
import { Contract } from '../../common/contract'
|
|
|
|
import { User } from '../../common/user'
|
2021-12-11 00:06:17 +00:00
|
|
|
|
|
|
|
export const getValue = async <T>(collection: string, doc: string) => {
|
2022-01-07 00:05:48 +00:00
|
|
|
const snap = await admin.firestore().collection(collection).doc(doc).get()
|
2021-12-11 00:06:17 +00:00
|
|
|
|
2022-01-07 00:05:48 +00:00
|
|
|
return snap.exists ? (snap.data() as T) : undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getValues = async <T>(query: admin.firestore.Query) => {
|
|
|
|
const snap = await query.get()
|
|
|
|
return snap.docs.map((doc) => doc.data() as T)
|
2021-12-11 00:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const getContract = (contractId: string) => {
|
|
|
|
return getValue<Contract>('contracts', contractId)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getUser = (userId: string) => {
|
|
|
|
return getValue<User>('users', userId)
|
2022-01-07 00:05:48 +00:00
|
|
|
}
|