mirror of
https://github.com/docmost/docmost.git
synced 2026-05-21 09:14:07 +08:00
4913975e99
* fix transaction usgae in repos * other bug fixes
52 lines
1.3 KiB
TypeScript
52 lines
1.3 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,
|
|
workspaceId: string,
|
|
): Promise<Attachment> {
|
|
return this.db
|
|
.selectFrom('attachments')
|
|
.selectAll()
|
|
.where('id', '=', attachmentId)
|
|
.where('workspaceId', '=', workspaceId)
|
|
.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<void> {
|
|
await this.db
|
|
.updateTable('attachments')
|
|
.set(updatableAttachment)
|
|
.where('id', '=', attachmentId)
|
|
.returningAll()
|
|
.executeTakeFirst();
|
|
}
|
|
}
|