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

View File

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