more work on attachments

* fix frontend env usage
This commit is contained in:
Philipinho
2024-05-22 23:24:57 +01:00
parent b06a78b6ec
commit ccf9d5d99f
31 changed files with 612 additions and 349 deletions

View File

@ -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(),
)

View File

@ -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()`),
)

View File

@ -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();
}
}

View File

@ -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))

View File

@ -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)

View File

@ -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)

View File

@ -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>;