fetch page without ydoc

This commit is contained in:
Philipinho
2023-10-30 14:46:28 +00:00
parent f16df902c7
commit 730e925b6a
3 changed files with 38 additions and 9 deletions

View File

@ -27,9 +27,10 @@ export class PageController {
private readonly workspaceService: WorkspaceService,
) {}
@HttpCode(HttpStatus.OK)
@Post('/details')
async getPage(@Body() input: PageDetailsDto) {
return this.pageService.findById(input.id);
return this.pageService.findWithoutYDoc(input.id);
}
@HttpCode(HttpStatus.CREATED)
@ -47,16 +48,19 @@ export class PageController {
return this.pageService.create(userId, workspaceId, createPageDto);
}
@HttpCode(HttpStatus.OK)
@Post('update')
async update(@Body() updatePageDto: UpdatePageDto) {
return this.pageService.update(updatePageDto.id, updatePageDto);
}
@HttpCode(HttpStatus.OK)
@Post('delete')
async delete(@Body() deletePageDto: DeletePageDto) {
await this.pageService.delete(deletePageDto.id);
}
@HttpCode(HttpStatus.OK)
@Post('restore')
async restore(@Body() deletePageDto: DeletePageDto) {
await this.pageService.restore(deletePageDto.id);

View File

@ -11,4 +11,30 @@ export class PageRepository extends Repository<Page> {
async findById(pageId: string) {
return this.findOneBy({ id: pageId });
}
async findWithoutYDoc(pageId: string) {
return this.dataSource
.createQueryBuilder(Page, 'page')
.where('page.id = :id', { id: pageId })
.select([
'page.id',
'page.title',
'page.slug',
'page.icon',
'page.coverPhoto',
'page.editor',
'page.shareId',
'page.parentPageId',
'page.creatorId',
'page.workspaceId',
'page.isLocked',
'page.status',
'page.publishedAt',
'page.createdAt',
'page.updatedAt',
'page.deletedAt',
'page.children',
])
.getOne();
}
}

View File

@ -28,6 +28,10 @@ export class PageService {
return this.pageRepository.findById(pageId);
}
async findWithoutYDoc(pageId: string) {
return this.pageRepository.findWithoutYDoc(pageId);
}
async create(
userId: string,
workspaceId: string,
@ -59,17 +63,12 @@ export class PageService {
}
async update(pageId: string, updatePageDto: UpdatePageDto): Promise<Page> {
const existingPage = await this.pageRepository.findOne({
where: { id: pageId },
});
if (!existingPage) {
const result = await this.pageRepository.update(pageId, updatePageDto);
if (result.affected === 0) {
throw new BadRequestException(`Page not found`);
}
Object.assign(existingPage, updatePageDto);
return await this.pageRepository.save(existingPage);
return await this.pageRepository.findWithoutYDoc(pageId);
}
async updateState(pageId: string, content: any, ydoc: any): Promise<void> {