feat: add page stats to page menu (#876)

This commit is contained in:
Philip Okugbe
2025-03-13 14:54:18 +00:00
committed by GitHub
parent f7a14e23cd
commit f45d9dc5a0
8 changed files with 111 additions and 7 deletions

View File

@ -44,6 +44,8 @@ export class PageController {
const page = await this.pageRepo.findById(dto.pageId, {
includeSpace: true,
includeContent: true,
includeCreator: true,
includeLastUpdatedBy: true,
});
if (!page) {

View File

@ -46,6 +46,8 @@ export class PageRepo {
includeContent?: boolean;
includeYdoc?: boolean;
includeSpace?: boolean;
includeCreator?: boolean;
includeLastUpdatedBy?: boolean;
withLock?: boolean;
trx?: KyselyTransaction;
},
@ -58,6 +60,14 @@ export class PageRepo {
.$if(opts?.includeContent, (qb) => qb.select('content'))
.$if(opts?.includeYdoc, (qb) => qb.select('ydoc'));
if (opts?.includeCreator) {
query = query.select((eb) => this.withCreator(eb));
}
if (opts?.includeLastUpdatedBy) {
query = query.select((eb) => this.withLastUpdatedBy(eb));
}
if (opts?.includeSpace) {
query = query.select((eb) => this.withSpace(eb));
}
@ -161,6 +171,24 @@ export class PageRepo {
).as('space');
}
withCreator(eb: ExpressionBuilder<DB, 'pages'>) {
return jsonObjectFrom(
eb
.selectFrom('users')
.select(['users.id', 'users.name', 'users.avatarUrl'])
.whereRef('users.id', '=', 'pages.creatorId'),
).as('creator');
}
withLastUpdatedBy(eb: ExpressionBuilder<DB, 'pages'>) {
return jsonObjectFrom(
eb
.selectFrom('users')
.select(['users.id', 'users.name', 'users.avatarUrl'])
.whereRef('users.id', '=', 'pages.lastUpdatedById'),
).as('lastUpdatedBy');
}
async getPageAndDescendants(parentPageId: string) {
return this.db
.withRecursive('page_hierarchy', (db) =>