support get and delete on documents
This commit is contained in:
@@ -26,6 +26,36 @@ class DocumentsService extends EventEmitter<DocumentEvents> {
|
||||
this.#services = services;
|
||||
}
|
||||
|
||||
public get = async (uri: string, type: string) => {
|
||||
const db = await this.#services.get(DatabaseService).getDb();
|
||||
const [document] = await db<TableRow['document']>(tableNames.documents)
|
||||
.where({
|
||||
uri,
|
||||
type,
|
||||
})
|
||||
.limit(1);
|
||||
return document;
|
||||
};
|
||||
|
||||
public delete = async (uri: string, type: string) => {
|
||||
const db = await this.#services.get(DatabaseService).getDb();
|
||||
const [document] = await db<TableRow['document']>(tableNames.documents)
|
||||
.where({
|
||||
uri,
|
||||
type,
|
||||
})
|
||||
.limit(1);
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
const toDelete: Document = {
|
||||
...document,
|
||||
deletedAt: new Date().toISOString(),
|
||||
};
|
||||
await db(tableNames.documents).where({ uri, type }).update(toDelete);
|
||||
this.emit('upsert', { action: 'delete', document: toDelete });
|
||||
};
|
||||
|
||||
public upsert = async (document: DocumentUpsert) => {
|
||||
const db = await this.#services.get(DatabaseService).getDb();
|
||||
const [current] = await db<TableRow['document']>(tableNames.documents)
|
||||
|
||||
Reference in New Issue
Block a user