chore: fix linting

This commit is contained in:
Travis Fischer
2021-01-27 18:42:11 -05:00
parent 02640c96de
commit da29754f6e
13 changed files with 294 additions and 104 deletions

View File

@@ -1,5 +1,4 @@
import * as firestore from '@google-cloud/firestore'
import * as types from './types'
import * as config from './config'
export let db: firestore.Firestore = null
@@ -13,42 +12,3 @@ if (config.isPreviewImageSupportEnabled) {
images = db.collection(config.firebaseCollectionImages)
}
async function get<T extends types.Model>(
doc: firestore.DocumentReference,
userId?: string
): Promise<T> {
const snapshot = await doc.get()
if (snapshot.exists) {
const res = getSnapshot<T>(snapshot)
if (userId && res.userId && res.userId !== userId) {
throw {
message: 'Unauthorized',
status: 403
}
}
return res
}
throw {
message: 'Not found',
status: 404
}
}
function getSnapshot<T extends types.Model>(
snapshot: firestore.DocumentSnapshot<firestore.DocumentData>
): T {
const data = snapshot.data()
delete data.timestamp
return {
...data,
id: snapshot.id,
createdAt: (snapshot.createTime.toDate().getTime() / 1000) | 0,
updatedAt: (snapshot.updateTime.toDate().getTime() / 1000) | 0
} as T
}