diff options
author | eleanor-park <eleanor_park@brown.edu> | 2024-08-27 16:44:12 -0400 |
---|---|---|
committer | eleanor-park <eleanor_park@brown.edu> | 2024-08-27 16:44:12 -0400 |
commit | 39d2bba7bf4b0cc3759931691640083a48cce662 (patch) | |
tree | 8bf110760aa926237b6294aec545f48cfc92747d /src/server/database.ts | |
parent | 6f73686ec4dc3e01ae3eacc0150aa59eafea0325 (diff) | |
parent | b8a04a0fedf8ef3612395764a0ecd01f6824ebd1 (diff) |
Merge branch 'master' into eleanor-gptdraw
Diffstat (limited to 'src/server/database.ts')
-rw-r--r-- | src/server/database.ts | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/server/database.ts b/src/server/database.ts index ff8584cd7..10dc540c3 100644 --- a/src/server/database.ts +++ b/src/server/database.ts @@ -5,11 +5,11 @@ import { emptyFunction, Utils } from '../Utils'; import { GoogleApiServerUtils } from './apis/google/GoogleApiServerUtils'; import { DocumentsCollection, IDatabase } from './IDatabase'; import { MemoryDatabase } from './MemoryDatabase'; -import { Transferable } from './Message'; import { Upload } from './SharedMediaTypes'; +import { serializedDoctype } from '../fields/ObjectField'; export namespace Database { - export let disconnect: Function; + export let disconnect: () => void; class DocSchema implements mongodb.BSON.Document { _id!: string; @@ -31,7 +31,7 @@ export namespace Database { try { const { connection } = mongoose; disconnect = async () => - new Promise<any>(resolve => { + new Promise<void>(resolve => { connection.close().then(resolve); }); if (connection.readyState === ConnectionStates.disconnected) { @@ -84,6 +84,7 @@ export namespace Database { if (this.db) { const collection = this.db.collection<DocSchema>(collectionName); const prom = this.currentWrites[id]; + // eslint-disable-next-line prefer-const let newProm: Promise<void>; const run = (): Promise<void> => new Promise<void>(resolve => { @@ -112,6 +113,7 @@ export namespace Database { if (this.db) { const collection = this.db.collection<DocSchema>(collectionName); const prom = this.currentWrites[id]; + // eslint-disable-next-line prefer-const let newProm: Promise<void>; const run = (): Promise<void> => new Promise<void>(resolve => { @@ -145,9 +147,7 @@ export namespace Database { } public delete(query: any, collectionName?: string): Promise<mongodb.DeleteResult>; - // eslint-disable-next-line no-dupe-class-members public delete(id: string, collectionName?: string): Promise<mongodb.DeleteResult>; - // eslint-disable-next-line no-dupe-class-members public delete(idIn: any, collectionName = DocumentsCollection) { let id = idIn; if (typeof id === 'string') { @@ -196,6 +196,7 @@ export namespace Database { const id = value._id; const collection = this.db.collection<DocSchema>(collectionName); const prom = this.currentWrites[id]; + // eslint-disable-next-line prefer-const let newProm: Promise<void>; const run = (): Promise<void> => new Promise<void>(resolve => { @@ -219,7 +220,7 @@ export namespace Database { return undefined; } - public getDocument(id: string, fn: (result?: Transferable) => void, collectionName = DocumentsCollection) { + public getDocument(id: string, fn: (result?: serializedDoctype) => void, collectionName = DocumentsCollection) { if (this.db) { const collection = this.db.collection<DocSchema>(collectionName); collection.findOne({ _id: id }).then(resultIn => { @@ -237,7 +238,7 @@ export namespace Database { } } - public async getDocuments(ids: string[], fn: (result: Transferable[]) => void, collectionName = DocumentsCollection) { + public async getDocuments(ids: string[], fn: (result: serializedDoctype[]) => void, collectionName = DocumentsCollection) { if (this.db) { const found = await this.db .collection<DocSchema>(collectionName) |