diff --git a/functions/src/callable/exchange-token.ts b/functions/src/callable/exchange-token.ts index 7a36e712..29db0547 100644 --- a/functions/src/callable/exchange-token.ts +++ b/functions/src/callable/exchange-token.ts @@ -3,6 +3,8 @@ import * as functions from 'firebase-functions'; import {verify} from 'jsonwebtoken'; import {ENV_CONFIG} from '../consts/env-config.const'; import {SHARED_CONFIG, Collections} from 'definitions'; +import {DbService} from '../services/database/db.service'; + export const exchangeToken = functions .region(SHARED_CONFIG.cloudRegion) @@ -21,7 +23,7 @@ export const exchangeToken = functions const [token, user] = await Promise.all([ auth.createCustomToken(decoded.id), (data.pullUser !== false ? - firestore.collection(Collections.Users).doc(decoded.id).get() : + new DbService().getDocument(Collections.Users, decoded.id) : Promise.resolve()) as any ]); diff --git a/functions/src/callable/update-email.ts b/functions/src/callable/update-email.ts index 78773a73..7b1c85ec 100644 --- a/functions/src/callable/update-email.ts +++ b/functions/src/callable/update-email.ts @@ -1,6 +1,7 @@ import {Collections, SHARED_CONFIG} from 'definitions'; import {auth, firestore} from 'firebase-admin'; import * as functions from 'firebase-functions'; +import {DbService} from '../services/database/db.service'; import {hasPermission} from '../utils/auth'; import {schemaValidation} from '../utils/schema-validation'; @@ -27,9 +28,10 @@ export const updateEmail = functions try { await auth().updateUser(id, {email}); - await firestore().collection(Collections.Users).doc(id).update({ - email - }); + await new DbService().updateDocument(Collections.Users, id, {email}); + // await firestore().collection(Collections.Users).doc(id).update({ + // email + // }); } catch (e) { functions.logger.error(e); throw new functions.https.HttpsError('internal', e.toString()); diff --git a/functions/src/services/database/db.service.ts b/functions/src/services/database/db.service.ts new file mode 100644 index 00000000..d23ade8e --- /dev/null +++ b/functions/src/services/database/db.service.ts @@ -0,0 +1,10 @@ +export class DbService { + getDocument(moduleId, id): Promise { + return Promise.resolve([]); + } + + updateDocument(moduleId, id, data): Promise { + return Promise.resolve([]); + } + +} diff --git a/functions/src/services/database/firebase.service.ts b/functions/src/services/database/firebase.service.ts new file mode 100644 index 00000000..c77232a5 --- /dev/null +++ b/functions/src/services/database/firebase.service.ts @@ -0,0 +1,13 @@ +import * as admin from 'firebase-admin'; +import {DbService} from './db.service'; +export abstract class FirebaseDatabaseService extends DbService { + + getDocument(moduleId, id): Promise { + return admin.firestore().collection(moduleId).doc(id).get(); + } + + updateDocument(moduleId, id, data): Promise { + return admin.firestore().collection(moduleId).doc(id).update(data); + } + +}