Skip to content

Commit

Permalink
feat: working on dbService for multiple databases #449
Browse files Browse the repository at this point in the history
  • Loading branch information
svendjanis committed Dec 5, 2022
1 parent 50b189c commit 305c259
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions functions/src/callable/exchange-token.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Collections, SHARED_CONFIG} from 'definitions';
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import {verify} from 'jsonwebtoken';
import {dbService} from '../consts/dbService.const';
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
Expand All @@ -23,7 +23,7 @@ export const exchangeToken = functions
const [token, user] = await Promise.all([
auth.createCustomToken(decoded.id),
(data.pullUser !== false ?
new DbService().getDocument(Collections.Users, decoded.id) :
dbService.getDocument(Collections.Users, decoded.id) :
Promise.resolve()) as any
]);

Expand Down
6 changes: 3 additions & 3 deletions functions/src/callable/update-email.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Collections, SHARED_CONFIG} from 'definitions';
import {auth, firestore} from 'firebase-admin';
import {auth} from 'firebase-admin';
import * as functions from 'firebase-functions';
import {DbService} from '../services/database/db.service';
import {dbService} from '../consts/dbService.const';
import {hasPermission} from '../utils/auth';
import {schemaValidation} from '../utils/schema-validation';

Expand All @@ -28,7 +28,7 @@ export const updateEmail = functions

try {
await auth().updateUser(id, {email});
await new DbService().updateDocument(Collections.Users, id, {email});
await dbService.updateDocument(Collections.Users, id, {email});
// await firestore().collection(Collections.Users).doc(id).update({
// email
// });
Expand Down
4 changes: 2 additions & 2 deletions functions/src/services/database/db.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export class DbService {
getDocument(moduleId, id): Promise<any> {
static getDocument(moduleId, id): Promise<any> {
return Promise.resolve([]);
}

updateDocument(moduleId, id, data): Promise<any> {
static updateDocument(moduleId, id, data): Promise<any> {
return Promise.resolve([]);
}

Expand Down
2 changes: 1 addition & 1 deletion functions/src/services/database/firebase.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as admin from 'firebase-admin';
import {DbService} from './db.service';
export abstract class FirebaseDatabaseService extends DbService {
export class FirebaseDatabaseService extends DbService {

getDocument(moduleId, id): Promise<any> {
return admin.firestore().collection(moduleId).doc(id).get();
Expand Down

0 comments on commit 305c259

Please sign in to comment.