feat: add page meta api

This commit is contained in:
DarkSky
2024-08-21 14:57:57 +08:00
parent 266607e3ae
commit 0417c70d54
6 changed files with 155 additions and 10 deletions
@@ -12,19 +12,11 @@ import {
import type { SnapshotHistory } from '@prisma/client';
import { CurrentUser } from '../../auth';
import { type Editor, PgWorkspaceDocStorageAdapter } from '../../doc';
import { PgWorkspaceDocStorageAdapter } from '../../doc';
import { Permission, PermissionService } from '../../permission';
import { DocID } from '../../utils/doc';
import { WorkspaceType } from '../types';
@ObjectType()
class EditorType implements Partial<Editor> {
@Field()
name!: string;
@Field(() => String, { nullable: true })
avatarUrl!: string | null;
}
import { EditorType } from './workspace';
@ObjectType()
class DocHistoryType implements Partial<SnapshotHistory> {
@@ -1,8 +1,10 @@
import { Logger } from '@nestjs/common';
import {
Args,
Field,
Int,
Mutation,
ObjectType,
Parent,
Query,
ResolveField,
@@ -16,6 +18,7 @@ import { applyUpdate, Doc } from 'yjs';
import type { FileUpload } from '../../../fundamentals';
import {
CantChangeSpaceOwner,
DocNotFound,
EventEmitter,
InternalServerError,
MailService,
@@ -28,6 +31,7 @@ import {
UserNotFound,
} from '../../../fundamentals';
import { CurrentUser, Public } from '../../auth';
import type { Editor } from '../../doc';
import { Permission, PermissionService } from '../../permission';
import { QuotaManagementService, QuotaQueryType } from '../../quota';
import { WorkspaceBlobStorage } from '../../storage';
@@ -40,6 +44,30 @@ import {
} from '../types';
import { defaultWorkspaceAvatar } from '../utils';
@ObjectType()
export class EditorType implements Partial<Editor> {
@Field()
name!: string;
@Field(() => String, { nullable: true })
avatarUrl!: string | null;
}
@ObjectType()
class WorkspacePageMeta {
@Field(() => Date)
createdAt!: Date;
@Field(() => Date)
updatedAt!: Date;
@Field(() => EditorType, { nullable: true })
createdBy!: EditorType | null;
@Field(() => EditorType, { nullable: true })
updatedBy!: EditorType | null;
}
/**
* Workspace resolver
* Public apis rate limit: 10 req/m
@@ -140,6 +168,35 @@ export class WorkspaceResolver {
}));
}
@ResolveField(() => WorkspacePageMeta, {
description: 'Cloud page metadata of workspace',
complexity: 2,
})
async pageMeta(
@Parent() workspace: WorkspaceType,
@Args('pageId') pageId: string
) {
const metadata = await this.prisma.snapshot.findFirst({
where: { workspaceId: workspace.id, id: pageId },
select: {
createdAt: true,
updatedAt: true,
createdByUser: { select: { name: true, avatarUrl: true } },
updatedByUser: { select: { name: true, avatarUrl: true } },
},
});
if (!metadata) {
throw new DocNotFound({ spaceId: workspace.id, docId: pageId });
}
return {
createdAt: metadata.createdAt,
updatedAt: metadata.updatedAt,
createdBy: metadata.createdByUser || null,
updatedBy: metadata.updatedByUser || null,
};
}
@ResolveField(() => QuotaQueryType, {
name: 'quota',
description: 'quota of workspace',
+10
View File
@@ -881,6 +881,13 @@ type WorkspacePage {
workspaceId: String!
}
type WorkspacePageMeta {
createdAt: DateTime!
createdBy: EditorType
updatedAt: DateTime!
updatedBy: EditorType
}
type WorkspaceType {
"""Available features of workspace"""
availableFeatures: [FeatureType!]!
@@ -908,6 +915,9 @@ type WorkspaceType {
"""Owner of workspace"""
owner: UserType!
"""Cloud page metadata of workspace"""
pageMeta(pageId: String!): WorkspacePageMeta!
"""Permission of current signed in user in workspace"""
permission: Permission!