mirror of
https://github.com/docmost/docmost.git
synced 2025-11-12 14:22:36 +10:00
feat: add page stats to page menu (#876)
This commit is contained in:
@ -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) {
|
||||
|
||||
@ -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) =>
|
||||
|
||||
Reference in New Issue
Block a user