mirror of
https://github.com/Shadowfita/docmost.git
synced 2025-11-25 22:21:03 +10:00
add recent changes tab to home
This commit is contained in:
@ -23,7 +23,7 @@ export class PageOrdering {
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
entityType: string;
|
||||
|
||||
@Column('uuid', { array: true, default: () => 'ARRAY[]::uuid[]' })
|
||||
@Column('uuid', { array: true })
|
||||
childrenIds: string[];
|
||||
|
||||
@ManyToOne(() => Workspace, (workspace) => workspace.id, {
|
||||
|
||||
@ -55,6 +55,20 @@ export class Page {
|
||||
@JoinColumn({ name: 'creatorId' })
|
||||
creator: User;
|
||||
|
||||
@Column({ type: 'uuid', nullable: true })
|
||||
lastUpdatedById: string;
|
||||
|
||||
@ManyToOne(() => User)
|
||||
@JoinColumn({ name: 'lastUpdatedById' })
|
||||
lastUpdatedBy: User;
|
||||
|
||||
@Column({ type: 'uuid', nullable: true })
|
||||
deletedById: string;
|
||||
|
||||
@ManyToOne(() => User)
|
||||
@JoinColumn({ name: 'deletedById' })
|
||||
deletedBy: User;
|
||||
|
||||
@Column()
|
||||
workspaceId: string;
|
||||
|
||||
|
||||
@ -50,8 +50,14 @@ export class PageController {
|
||||
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Post('update')
|
||||
async update(@Body() updatePageDto: UpdatePageDto) {
|
||||
return this.pageService.update(updatePageDto.id, updatePageDto);
|
||||
async update(
|
||||
@Req() req: FastifyRequest,
|
||||
@Body() updatePageDto: UpdatePageDto,
|
||||
) {
|
||||
const jwtPayload = req['user'];
|
||||
const userId = jwtPayload.sub;
|
||||
|
||||
return this.pageService.update(updatePageDto.id, updatePageDto, userId);
|
||||
}
|
||||
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ -72,6 +78,16 @@ export class PageController {
|
||||
return this.pageOrderService.movePage(movePageDto);
|
||||
}
|
||||
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Post('recent')
|
||||
async getRecentWorkspacePages(@Req() req: FastifyRequest) {
|
||||
const jwtPayload = req['user'];
|
||||
const workspaceId = (
|
||||
await this.workspaceService.getUserCurrentWorkspace(jwtPayload.sub)
|
||||
).id;
|
||||
return this.pageService.getRecentWorkspacePages(workspaceId);
|
||||
}
|
||||
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Post()
|
||||
async getWorkspacePages(@Req() req: FastifyRequest) {
|
||||
@ -79,7 +95,7 @@ export class PageController {
|
||||
const workspaceId = (
|
||||
await this.workspaceService.getUserCurrentWorkspace(jwtPayload.sub)
|
||||
).id;
|
||||
return this.pageService.getByWorkspaceId(workspaceId);
|
||||
return this.pageService.getSidebarPagesByWorkspaceId(workspaceId);
|
||||
}
|
||||
|
||||
@HttpCode(HttpStatus.OK)
|
||||
|
||||
@ -26,6 +26,7 @@ export class PageRepository extends Repository<Page> {
|
||||
'page.shareId',
|
||||
'page.parentPageId',
|
||||
'page.creatorId',
|
||||
'page.lastUpdatedById',
|
||||
'page.workspaceId',
|
||||
'page.isLocked',
|
||||
'page.status',
|
||||
|
||||
@ -52,8 +52,6 @@ export class PageOrderingService {
|
||||
|
||||
orderPageList(workspaceOrdering.childrenIds, dto);
|
||||
|
||||
console.log(workspaceOrdering.childrenIds);
|
||||
|
||||
await manager.save(workspaceOrdering);
|
||||
} else {
|
||||
const parentPageId = dto.parentId;
|
||||
@ -236,8 +234,8 @@ export class PageOrderingService {
|
||||
manager: EntityManager,
|
||||
): Promise<PageOrdering> {
|
||||
await manager.query(
|
||||
`INSERT INTO page_ordering ("entityId", "entityType", "workspaceId")
|
||||
VALUES ($1, $2, $3)
|
||||
`INSERT INTO page_ordering ("entityId", "entityType", "workspaceId", "childrenIds")
|
||||
VALUES ($1, $2, $3, '{}')
|
||||
ON CONFLICT ("entityId", "entityType") DO NOTHING`,
|
||||
[entityId, entityType, workspaceId],
|
||||
);
|
||||
@ -260,7 +258,7 @@ export class PageOrderingService {
|
||||
const workspaceOrder = await this.getWorkspacePageOrder(workspaceId);
|
||||
|
||||
const pageOrder = workspaceOrder ? workspaceOrder.childrenIds : undefined;
|
||||
const pages = await this.pageService.getByWorkspaceId(workspaceId);
|
||||
const pages = await this.pageService.getSidebarPagesByWorkspaceId(workspaceId);
|
||||
|
||||
const pageMap: { [id: string]: PageWithOrderingDto } = {};
|
||||
pages.forEach((page) => {
|
||||
|
||||
@ -47,6 +47,7 @@ export class PageService {
|
||||
const page = plainToInstance(Page, createPageDto);
|
||||
page.creatorId = userId;
|
||||
page.workspaceId = workspaceId;
|
||||
page.lastUpdatedById = userId;
|
||||
|
||||
if (createPageDto.parentPageId) {
|
||||
// TODO: make sure parent page belongs to same workspace and user has permissions
|
||||
@ -69,8 +70,17 @@ export class PageService {
|
||||
return createdPage;
|
||||
}
|
||||
|
||||
async update(pageId: string, updatePageDto: UpdatePageDto): Promise<Page> {
|
||||
const result = await this.pageRepository.update(pageId, updatePageDto);
|
||||
async update(
|
||||
pageId: string,
|
||||
updatePageDto: UpdatePageDto,
|
||||
userId: string,
|
||||
): Promise<Page> {
|
||||
const updateData = {
|
||||
...updatePageDto,
|
||||
lastUpdatedById: userId,
|
||||
};
|
||||
|
||||
const result = await this.pageRepository.update(pageId, updateData);
|
||||
if (result.affected === 0) {
|
||||
throw new BadRequestException(`Page not found`);
|
||||
}
|
||||
@ -78,10 +88,16 @@ export class PageService {
|
||||
return await this.pageRepository.findWithoutYDoc(pageId);
|
||||
}
|
||||
|
||||
async updateState(pageId: string, content: any, ydoc: any): Promise<void> {
|
||||
async updateState(
|
||||
pageId: string,
|
||||
content: any,
|
||||
ydoc: any,
|
||||
userId?: string, // TODO: fix this
|
||||
): Promise<void> {
|
||||
await this.pageRepository.update(pageId, {
|
||||
content: content,
|
||||
ydoc: ydoc,
|
||||
...(userId && { lastUpdatedById: userId }),
|
||||
});
|
||||
}
|
||||
|
||||
@ -187,16 +203,7 @@ export class PageService {
|
||||
return await this.pageRepository.findById(pageId);
|
||||
}
|
||||
|
||||
async getRecentPages(limit = 10): Promise<Page[]> {
|
||||
return await this.pageRepository.find({
|
||||
order: {
|
||||
createdAt: 'DESC',
|
||||
},
|
||||
take: limit,
|
||||
});
|
||||
}
|
||||
|
||||
async getByWorkspaceId(
|
||||
async getSidebarPagesByWorkspaceId(
|
||||
workspaceId: string,
|
||||
limit = 200,
|
||||
): Promise<PageWithOrderingDto[]> {
|
||||
@ -224,4 +231,38 @@ export class PageService {
|
||||
|
||||
return transformPageResult(pages);
|
||||
}
|
||||
|
||||
async getRecentWorkspacePages(
|
||||
workspaceId: string,
|
||||
limit = 20,
|
||||
offset = 0,
|
||||
): Promise<Page[]> {
|
||||
const pages = await this.pageRepository
|
||||
.createQueryBuilder('page')
|
||||
.where('page.workspaceId = :workspaceId', { workspaceId })
|
||||
.select([
|
||||
'page.id',
|
||||
'page.title',
|
||||
'page.slug',
|
||||
'page.icon',
|
||||
'page.coverPhoto',
|
||||
'page.editor',
|
||||
'page.shareId',
|
||||
'page.parentPageId',
|
||||
'page.creatorId',
|
||||
'page.lastUpdatedById',
|
||||
'page.workspaceId',
|
||||
'page.isLocked',
|
||||
'page.status',
|
||||
'page.publishedAt',
|
||||
'page.createdAt',
|
||||
'page.updatedAt',
|
||||
'page.deletedAt',
|
||||
])
|
||||
.orderBy('page.updatedAt', 'DESC')
|
||||
.offset(offset)
|
||||
.take(limit)
|
||||
.getMany();
|
||||
return pages;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user