aboutsummaryrefslogtreecommitdiff
path: root/src/server/database.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/database.ts')
-rw-r--r--src/server/database.ts15
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)