mirror of
https://github.com/Shadowfita/docmost.git
synced 2025-11-20 19:51:02 +10:00
* update tiptap version * excalidraw init * cleanup * better file handling and other fixes * use different modal to fix excalidraw cursor position issue * see https://github.com/excalidraw/excalidraw/issues/7312 * fix websocket in vite dev mode * WIP * add align attribute * fix table * menu icons * Render image in excalidraw html * add size to custom SVG components * rewrite undefined font urls
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { InjectKysely } from 'nestjs-kysely';
|
|
import { KyselyDB, KyselyTransaction } from '@docmost/db/types/kysely.types';
|
|
import { dbOrTx } from '@docmost/db/utils';
|
|
import {
|
|
Attachment,
|
|
InsertableAttachment,
|
|
UpdatableAttachment,
|
|
} from '@docmost/db/types/entity.types';
|
|
|
|
@Injectable()
|
|
export class AttachmentRepo {
|
|
constructor(@InjectKysely() private readonly db: KyselyDB) {}
|
|
|
|
async findById(
|
|
attachmentId: string,
|
|
opts?: {
|
|
trx?: KyselyTransaction;
|
|
},
|
|
): Promise<Attachment> {
|
|
const db = dbOrTx(this.db, opts?.trx);
|
|
|
|
return db
|
|
.selectFrom('attachments')
|
|
.selectAll()
|
|
.where('id', '=', attachmentId)
|
|
.executeTakeFirst();
|
|
}
|
|
|
|
async insertAttachment(
|
|
insertableAttachment: InsertableAttachment,
|
|
trx?: KyselyTransaction,
|
|
): Promise<Attachment> {
|
|
const db = dbOrTx(this.db, trx);
|
|
|
|
return db
|
|
.insertInto('attachments')
|
|
.values(insertableAttachment)
|
|
.returningAll()
|
|
.executeTakeFirst();
|
|
}
|
|
|
|
async updateAttachment(
|
|
updatableAttachment: UpdatableAttachment,
|
|
attachmentId: string,
|
|
): Promise<Attachment> {
|
|
return await this.db
|
|
.updateTable('attachments')
|
|
.set(updatableAttachment)
|
|
.where('id', '=', attachmentId)
|
|
.returningAll()
|
|
.executeTakeFirst();
|
|
}
|
|
|
|
async deleteAttachment(attachmentId: string): Promise<void> {
|
|
await this.db
|
|
.deleteFrom('attachments')
|
|
.where('id', '=', attachmentId)
|
|
.executeTakeFirst();
|
|
}
|
|
|
|
async deleteAttachmentByFilePath(attachmentFilePath: string): Promise<void> {
|
|
await this.db
|
|
.deleteFrom('attachments')
|
|
.where('filePath', '=', attachmentFilePath)
|
|
.executeTakeFirst();
|
|
}
|
|
}
|