Refactoring

* replace TypeORM with Kysely query builder
* refactor migrations
* other changes and fixes
This commit is contained in:
Philipinho
2024-03-29 01:46:11 +00:00
parent cacb5606b1
commit c18c9ae02b
122 changed files with 2619 additions and 3541 deletions

View File

@ -1,5 +1,4 @@
import { Module, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { UserModule } from '../core/user/user.module';
import { AuthModule } from '../core/auth/auth.module';
import { AuthenticationExtension } from './extensions/authentication.extension';
import { PersistenceExtension } from './extensions/persistence.extension';
@ -18,7 +17,7 @@ import { HistoryExtension } from './extensions/history.extension';
PersistenceExtension,
HistoryExtension,
],
imports: [UserModule, AuthModule, PageModule],
imports: [AuthModule, PageModule],
})
export class CollaborationModule implements OnModuleInit, OnModuleDestroy {
private collabWsAdapter: CollabWsAdapter;

View File

@ -1,13 +1,13 @@
import { Extension, onAuthenticatePayload } from '@hocuspocus/server';
import { UserService } from '../../core/user/user.service';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { TokenService } from '../../core/auth/services/token.service';
import { UserRepo } from '@docmost/db/repos/user/user.repo';
@Injectable()
export class AuthenticationExtension implements Extension {
constructor(
private tokenService: TokenService,
private userService: UserService,
private userRepo: UserRepo,
) {}
async onAuthenticate(data: onAuthenticatePayload) {
@ -22,7 +22,9 @@ export class AuthenticationExtension implements Extension {
}
const userId = jwtPayload.sub;
const user = await this.userService.findById(userId);
const workspaceId = jwtPayload.workspaceId;
const user = await this.userRepo.findById(userId, workspaceId);
if (!user) {
throw new UnauthorizedException();

View File

@ -53,7 +53,8 @@ export class HistoryExtension implements Extension {
async recordHistory(pageId: string) {
try {
const page = await this.pageService.findWithContent(pageId);
const includeContent = true;
const page = await this.pageService.findById(pageId, includeContent);
// Todo: compare if data is the same as the previous version
await this.pageHistoryService.saveHistory(page);
console.log(`New history created for: ${pageId}`);

View File

@ -21,7 +21,7 @@ export class PersistenceExtension implements Extension {
return;
}
const page = await this.pageService.findWithAllFields(pageId);
const page = await this.pageService.findById(pageId, true, true);
if (!page) {
console.log('page does not exist.');