* integrate websocket redis adapter
* use APP_SECRET for jwt signing
* auto migrate database on startup in production
* add updatedAt to update db operations
* create enterprise ee package directory
* fix comment editor focus
* other fixes
This commit is contained in:
Philipinho
2024-06-07 17:29:34 +01:00
parent eef9081aaf
commit 38ef610e5e
36 changed files with 541 additions and 166 deletions

View File

@ -54,7 +54,7 @@ export class GroupRepo {
): Promise<void> {
await this.db
.updateTable('groups')
.set(updatableGroup)
.set({ ...updatableGroup, updatedAt: new Date() })
.where('id', '=', groupId)
.where('workspaceId', '=', workspaceId)
.execute();

View File

@ -17,8 +17,13 @@ import { DB } from '@docmost/db/types/db';
export class PageHistoryRepo {
constructor(@InjectKysely() private readonly db: KyselyDB) {}
async findById(pageHistoryId: string): Promise<PageHistory> {
return await this.db
async findById(
pageHistoryId: string,
trx?: KyselyTransaction,
): Promise<PageHistory> {
const db = dbOrTx(this.db, trx);
return await db
.selectFrom('pageHistory')
.selectAll()
.select((eb) => this.withLastUpdatedBy(eb))
@ -38,18 +43,21 @@ export class PageHistoryRepo {
.executeTakeFirst();
}
async saveHistory(page: Page): Promise<void> {
await this.insertPageHistory({
pageId: page.id,
slugId: page.slugId,
title: page.title,
content: page.content,
icon: page.icon,
coverPhoto: page.coverPhoto,
lastUpdatedById: page.lastUpdatedById ?? page.creatorId,
spaceId: page.spaceId,
workspaceId: page.workspaceId,
});
async saveHistory(page: Page, trx?: KyselyTransaction): Promise<void> {
await this.insertPageHistory(
{
pageId: page.id,
slugId: page.slugId,
title: page.title,
content: page.content,
icon: page.icon,
coverPhoto: page.coverPhoto,
lastUpdatedById: page.lastUpdatedById ?? page.creatorId,
spaceId: page.spaceId,
workspaceId: page.workspaceId,
},
trx,
);
}
async findPageHistoryByPageId(pageId: string, pagination: PaginationOptions) {
@ -68,6 +76,18 @@ export class PageHistoryRepo {
return result;
}
async findPageLastHistory(pageId: string, trx?: KyselyTransaction) {
const db = dbOrTx(this.db, trx);
return await db
.selectFrom('pageHistory')
.selectAll()
.where('pageId', '=', pageId)
.limit(1)
.orderBy('createdAt', 'desc')
.executeTakeFirst();
}
withLastUpdatedBy(eb: ExpressionBuilder<DB, 'pageHistory'>) {
return jsonObjectFrom(
eb

View File

@ -46,9 +46,13 @@ export class PageRepo {
includeContent?: boolean;
includeYdoc?: boolean;
includeSpace?: boolean;
withLock?: boolean;
trx?: KyselyTransaction;
},
): Promise<Page> {
let query = this.db
const db = dbOrTx(this.db, opts?.trx);
let query = db
.selectFrom('pages')
.select(this.baseFields)
.$if(opts?.includeContent, (qb) => qb.select('content'))
@ -58,6 +62,10 @@ export class PageRepo {
query = query.select((eb) => this.withSpace(eb));
}
if (opts?.withLock && opts?.trx) {
query = query.forUpdate();
}
if (isValidUUID(pageId)) {
query = query.where('id', '=', pageId);
} else {
@ -73,7 +81,9 @@ export class PageRepo {
trx?: KyselyTransaction,
) {
const db = dbOrTx(this.db, trx);
let query = db.updateTable('pages').set(updatablePage);
let query = db
.updateTable('pages')
.set({ ...updatablePage, updatedAt: new Date() });
if (isValidUUID(pageId)) {
query = query.where('id', '=', pageId);

View File

@ -77,7 +77,7 @@ export class SpaceRepo {
const db = dbOrTx(this.db, trx);
return db
.updateTable('spaces')
.set(updatableSpace)
.set({ ...updatableSpace, updatedAt: new Date() })
.where('id', '=', spaceId)
.where('workspaceId', '=', workspaceId)
.returningAll()

View File

@ -80,7 +80,7 @@ export class UserRepo {
return await db
.updateTable('users')
.set(updatableUser)
.set({ ...updatableUser, updatedAt: new Date() })
.where('id', '=', userId)
.where('workspaceId', '=', workspaceId)
.execute();

View File

@ -53,7 +53,7 @@ export class WorkspaceRepo {
const db = dbOrTx(this.db, trx);
return db
.updateTable('workspaces')
.set(updatableWorkspace)
.set({ ...updatableWorkspace, updatedAt: new Date() })
.where('id', '=', workspaceId)
.execute();
}