updated page service & controller, recycle bin modal

This commit is contained in:
Eddy Oyieko
2024-09-20 12:07:51 +03:00
parent bda2dda12d
commit 9b04cfa0fe
6 changed files with 37 additions and 8 deletions

View File

@ -12,6 +12,7 @@ import { PageService } from './services/page.service';
import { CreatePageDto } from './dto/create-page.dto';
import { UpdatePageDto } from './dto/update-page.dto';
import { MovePageDto } from './dto/move-page.dto';
// import { RestorePageDto } from './dto/restore-page.dto';
import { PageHistoryIdDto, PageIdDto, PageInfoDto } from './dto/page.dto';
import { PageHistoryService } from './services/page-history.service';
import { AuthUser } from '../../common/decorators/auth-user.decorator';
@ -132,8 +133,19 @@ export class PageController {
@HttpCode(HttpStatus.OK)
@Post('restore')
async restore(@Body() pageIdDto: PageIdDto) {
await this.pageService.restore(pageIdDto.pageId);
async restore(@Body() pageIdDto: PageIdDto, @AuthUser() user: User) {
const page = await this.pageRepo.findById(pageIdDto.pageId);
if (!page) {
throw new NotFoundException('Page not found');
}
const ability = await this.spaceAbility.createForUser(user, page.spaceId);
if (ability.cannot(SpaceCaslAction.Manage, SpaceCaslSubject.Page)) {
throw new ForbiddenException();
}
await this.pageService.restore(pageIdDto.pageId);
}
@HttpCode(HttpStatus.OK)

View File

@ -162,9 +162,11 @@ export class PageService {
'parentPageId',
'spaceId',
'creatorId',
'deletedAt',
])
.select((eb) => this.withHasChildren(eb))
.orderBy('position', 'asc')
.where('deletedAt', 'is', null)
.where('spaceId', '=', spaceId);
if (pageId) {

View File

@ -148,6 +148,7 @@ export class PageRepo {
.select(this.baseFields)
.select((eb) => this.withSpace(eb))
.where('spaceId', '=', spaceId)
.where('deletedAt', 'is not', null)
.orderBy('updatedAt', 'desc');
const result = executeWithPagination(query, {
@ -166,6 +167,7 @@ export class PageRepo {
.select(this.baseFields)
.select((eb) => this.withSpace(eb))
.where('spaceId', 'in', userSpaceIds)
.where('deletedAt', 'is not', null)
.orderBy('updatedAt', 'desc');
const result = executeWithPagination(query, {