/*** import { Body, Controller, ForbiddenException, HttpCode, HttpStatus, NotFoundException, Post, UseGuards, } from '@nestjs/common'; import { WatcherService } from './watcher.service'; import { AuthUser } from '../../common/decorators/auth-user.decorator'; import { AuthWorkspace } from '../../common/decorators/auth-workspace.decorator'; import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard'; import { User, Workspace } from '@docmost/db/types/entity.types'; import { WatcherPageDto } from './dto/watcher.dto'; import { PageRepo } from '@docmost/db/repos/page/page.repo'; import SpaceAbilityFactory from '../casl/abilities/space-ability.factory'; import { SpaceCaslAction, SpaceCaslSubject, } from '../casl/interfaces/space-ability.type'; @UseGuards(JwtAuthGuard) @Controller('pages') export class WatcherController { constructor( private readonly watcherService: WatcherService, private readonly pageRepo: PageRepo, private readonly spaceAbility: SpaceAbilityFactory, ) {} @HttpCode(HttpStatus.OK) @Post('watch') async watchPage( @Body() dto: WatcherPageDto, @AuthUser() user: User, @AuthWorkspace() workspace: Workspace, ) { const page = await this.pageRepo.findById(dto.pageId); if (!page) { throw new NotFoundException('Page not found'); } const ability = await this.spaceAbility.createForUser(user, page.spaceId); if (ability.cannot(SpaceCaslAction.Read, SpaceCaslSubject.Page)) { throw new ForbiddenException(); } await this.watcherService.watchPage( user.id, page.id, page.spaceId, workspace.id, ); return { watching: true }; } @HttpCode(HttpStatus.OK) @Post('unwatch') async unwatchPage(@Body() dto: WatcherPageDto, @AuthUser() user: User) { const page = await this.pageRepo.findById(dto.pageId); if (!page) { throw new NotFoundException('Page not found'); } const ability = await this.spaceAbility.createForUser(user, page.spaceId); if (ability.cannot(SpaceCaslAction.Read, SpaceCaslSubject.Page)) { throw new ForbiddenException(); } await this.watcherService.unwatchPage(user.id, page.id); return { watching: false }; } @HttpCode(HttpStatus.OK) @Post('watch-status') async getWatchStatus(@Body() dto: WatcherPageDto, @AuthUser() user: User) { const page = await this.pageRepo.findById(dto.pageId); if (!page) { throw new NotFoundException('Page not found'); } const ability = await this.spaceAbility.createForUser(user, page.spaceId); if (ability.cannot(SpaceCaslAction.Read, SpaceCaslSubject.Page)) { throw new ForbiddenException(); } const watching = await this.watcherService.isWatchingPage(user.id, page.id); return { watching }; } } ***/