mirror of
https://github.com/docmost/docmost.git
synced 2025-11-14 20:01:09 +10:00
more work on attachments
* fix frontend env usage
This commit is contained in:
@ -10,7 +10,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
||||
.addColumn('name', 'varchar', (col) => col)
|
||||
.addColumn('description', 'text', (col) => col)
|
||||
.addColumn('slug', 'varchar', (col) => col)
|
||||
.addColumn('icon', 'varchar', (col) => col)
|
||||
.addColumn('logo', 'varchar', (col) => col)
|
||||
.addColumn('visibility', 'varchar', (col) =>
|
||||
col.defaultTo(SpaceVisibility.OPEN).notNull(),
|
||||
)
|
||||
|
||||
@ -15,9 +15,11 @@ export async function up(db: Kysely<any>): Promise<void> {
|
||||
.addColumn('creator_id', 'uuid', (col) =>
|
||||
col.references('users.id').notNull(),
|
||||
)
|
||||
.addColumn('page_id', 'uuid', (col) => col.references('pages.id'))
|
||||
.addColumn('space_id', 'uuid', (col) => col.references('spaces.id'))
|
||||
.addColumn('workspace_id', 'uuid', (col) => col.references('workspaces.id'))
|
||||
.addColumn('page_id', 'uuid', (col) => col)
|
||||
.addColumn('space_id', 'uuid', (col) => col)
|
||||
.addColumn('workspace_id', 'uuid', (col) =>
|
||||
col.references('workspaces.id').onDelete('cascade').notNull(),
|
||||
)
|
||||
.addColumn('created_at', 'timestamptz', (col) =>
|
||||
col.notNull().defaultTo(sql`now()`),
|
||||
)
|
||||
|
||||
@ -14,13 +14,16 @@ export class AttachmentRepo {
|
||||
|
||||
async findById(
|
||||
attachmentId: string,
|
||||
workspaceId: string,
|
||||
opts?: {
|
||||
trx?: KyselyTransaction;
|
||||
},
|
||||
): Promise<Attachment> {
|
||||
return this.db
|
||||
const db = dbOrTx(this.db, opts?.trx);
|
||||
|
||||
return db
|
||||
.selectFrom('attachments')
|
||||
.selectAll()
|
||||
.where('id', '=', attachmentId)
|
||||
.where('workspaceId', '=', workspaceId)
|
||||
.executeTakeFirst();
|
||||
}
|
||||
|
||||
@ -48,4 +51,18 @@ export class AttachmentRepo {
|
||||
.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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,9 +19,10 @@ export class SpaceRepo {
|
||||
async findById(
|
||||
spaceId: string,
|
||||
workspaceId: string,
|
||||
opts?: { includeMemberCount: boolean },
|
||||
opts?: { includeMemberCount?: boolean; trx?: KyselyTransaction },
|
||||
): Promise<Space> {
|
||||
return await this.db
|
||||
const db = dbOrTx(this.db, opts?.trx);
|
||||
return db
|
||||
.selectFrom('spaces')
|
||||
.selectAll('spaces')
|
||||
.$if(opts?.includeMemberCount, (qb) => qb.select(this.withMemberCount))
|
||||
|
||||
@ -70,8 +70,11 @@ export class UserRepo {
|
||||
updatableUser: UpdatableUser,
|
||||
userId: string,
|
||||
workspaceId: string,
|
||||
trx?: KyselyTransaction,
|
||||
) {
|
||||
return await this.db
|
||||
const db = dbOrTx(this.db, trx);
|
||||
|
||||
return await db
|
||||
.updateTable('users')
|
||||
.set(updatableUser)
|
||||
.where('id', '=', userId)
|
||||
|
||||
@ -13,8 +13,15 @@ import { sql } from 'kysely';
|
||||
export class WorkspaceRepo {
|
||||
constructor(@InjectKysely() private readonly db: KyselyDB) {}
|
||||
|
||||
async findById(workspaceId: string): Promise<Workspace> {
|
||||
return await this.db
|
||||
async findById(
|
||||
workspaceId: string,
|
||||
opts?: {
|
||||
trx?: KyselyTransaction;
|
||||
},
|
||||
): Promise<Workspace> {
|
||||
const db = dbOrTx(this.db, opts?.trx);
|
||||
|
||||
return db
|
||||
.selectFrom('workspaces')
|
||||
.selectAll()
|
||||
.where('id', '=', workspaceId)
|
||||
|
||||
4
apps/server/src/database/types/db.d.ts
vendored
4
apps/server/src/database/types/db.d.ts
vendored
@ -34,7 +34,7 @@ export interface Attachments {
|
||||
spaceId: string | null;
|
||||
type: string | null;
|
||||
updatedAt: Generated<Timestamp>;
|
||||
workspaceId: string | null;
|
||||
workspaceId: string;
|
||||
}
|
||||
|
||||
export interface Comments {
|
||||
@ -127,8 +127,8 @@ export interface Spaces {
|
||||
defaultRole: Generated<string>;
|
||||
deletedAt: Timestamp | null;
|
||||
description: string | null;
|
||||
icon: string | null;
|
||||
id: Generated<string>;
|
||||
logo: string | null;
|
||||
name: string | null;
|
||||
slug: string | null;
|
||||
updatedAt: Generated<Timestamp>;
|
||||
|
||||
Reference in New Issue
Block a user