aboutsummaryrefslogtreecommitdiff
path: root/src/server/database.ts
diff options
context:
space:
mode:
authorStanley Yip <stanley_yip@brown.edu>2019-10-13 15:58:23 -0400
committerStanley Yip <stanley_yip@brown.edu>2019-10-13 15:58:23 -0400
commitb50381f4872d4e5eaa6d1d8949ea4e10d468cfd8 (patch)
treec2939d230a5618aa609e4db84bfdee923bad80bd /src/server/database.ts
parentbd796f24677b2aacd32a371da6d2b7c7eb354018 (diff)
parentbaf6ed901d341cade58741d363bbc475519558ae (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into interaction_stanley
Diffstat (limited to 'src/server/database.ts')
-rw-r--r--src/server/database.ts12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/server/database.ts b/src/server/database.ts
index d2375ebd9..db86b472d 100644
--- a/src/server/database.ts
+++ b/src/server/database.ts
@@ -4,6 +4,7 @@ import { Opt } from '../new_fields/Doc';
import { Utils, emptyFunction } from '../Utils';
import { DashUploadUtils } from './DashUploadUtils';
import { Credentials } from 'google-auth-library';
+import { GoogleApiServerUtils } from './apis/google/GoogleApiServerUtils';
export namespace Database {
@@ -131,7 +132,7 @@ export namespace Database {
}
}
- public getDocument(id: string, fn: (result?: Transferable) => void, collectionName = Database.DocumentsCollection) {
+ public getDocument(id: string, fn: (result?: Transferable) => void, collectionName = "newDocuments") {
if (this.db) {
this.db.collection(collectionName).findOne({ _id: id }, (err, result) => {
if (result) {
@@ -165,7 +166,7 @@ export namespace Database {
}
}
- public async visit(ids: string[], fn: (result: any) => string[], collectionName = "newDocuments"): Promise<void> {
+ public async visit(ids: string[], fn: (result: any) => string[] | Promise<string[]>, collectionName = "newDocuments"): Promise<void> {
if (this.db) {
const visited = new Set<string>();
while (ids.length) {
@@ -179,10 +180,9 @@ export namespace Database {
for (const doc of docs) {
const id = doc.id;
visited.add(id);
- ids.push(...fn(doc));
+ ids.push(...(await fn(doc)));
}
}
-
} else {
return new Promise(res => {
this.onConnect.push(() => {
@@ -260,8 +260,8 @@ export namespace Database {
return SanitizedSingletonQuery<StoredCredentials>({ userId }, GoogleAuthentication, removeId);
};
- export const Write = async (userId: string, token: any) => {
- return Instance.insert({ userId, canAccess: [], ...token }, GoogleAuthentication);
+ export const Write = async (userId: string, enrichedCredentials: GoogleApiServerUtils.EnrichedCredentials) => {
+ return Instance.insert({ userId, canAccess: [], ...enrichedCredentials }, GoogleAuthentication);
};
export const Update = async (userId: string, access_token: string, expiry_date: number) => {