From e5c77ec309d40834b2d26a3bcf2a55fd03a224f6 Mon Sep 17 00:00:00 2001 From: e11sy Date: Mon, 22 Jul 2024 20:49:04 +0300 Subject: [PATCH] added note history shema --- src/presentation/http/http-api.ts | 3 + src/presentation/http/router/note.ts | 40 +++++++++++++ src/presentation/http/schema/History.ts | 76 +++++++++++++++++++++++++ 3 files changed, 119 insertions(+) diff --git a/src/presentation/http/http-api.ts b/src/presentation/http/http-api.ts index c3df80e6..31c1046a 100644 --- a/src/presentation/http/http-api.ts +++ b/src/presentation/http/http-api.ts @@ -19,6 +19,7 @@ import AIRouter from '@presentation/http/router/ai.js'; import EditorToolsRouter from './router/editorTools.js'; import { UserSchema } from './schema/User.js'; import { NoteSchema } from './schema/Note.js'; +import { HistotyRecordShema, HistoryMetaSchema } from './schema/History.js'; import { NoteSettingsSchema } from './schema/NoteSettings.js'; import { OauthSchema } from './schema/OauthSchema.js'; import Policies from './policies/index.js'; @@ -291,6 +292,8 @@ export default class HttpApi implements Api { private addSchema(): void { this.server?.addSchema(UserSchema); this.server?.addSchema(NoteSchema); + this.server?.addSchema(HistotyRecordShema); + this.server?.addSchema(HistoryMetaSchema); this.server?.addSchema(EditorToolSchema); this.server?.addSchema(NoteSettingsSchema); this.server?.addSchema(JoinSchemaParams); diff --git a/src/presentation/http/router/note.ts b/src/presentation/http/router/note.ts index 1e3e1436..e6cef567 100644 --- a/src/presentation/http/router/note.ts +++ b/src/presentation/http/router/note.ts @@ -667,6 +667,26 @@ const NoteRouter: FastifyPluginCallback = (fastify, opts, don 'userCanEdit', ], }, + schema: { + params: { + notePublicId: { + $ref: 'NoteSchema#/properties/id', + }, + }, + response: { + '2xx': { + type: 'object', + properties: { + noteHistoryMeta: { + type: 'array', + items: { + $ref: 'HistoryMetaSchema#', + }, + }, + }, + }, + }, + }, preHandler: [ noteResolver, ], @@ -701,6 +721,26 @@ const NoteRouter: FastifyPluginCallback = (fastify, opts, don 'userCanEdit', ], }, + schema: { + params: { + notePublicId: { + $ref: 'NoteSchema#/properties/id', + }, + historyId: { + $ref: 'NoteHistorySchema#/properties/id', + }, + }, + response: { + '2xx': { + type: 'object', + properties: { + noteHistoryRecord: { + $ref: 'NoteHistorySchema#', + }, + }, + }, + }, + }, preHandler: [ noteResolver, ], diff --git a/src/presentation/http/schema/History.ts b/src/presentation/http/schema/History.ts index 7c8b7681..a1b487c5 100644 --- a/src/presentation/http/schema/History.ts +++ b/src/presentation/http/schema/History.ts @@ -8,7 +8,83 @@ export const HistotyRecordShema = { 'content', 'id', 'userId', + 'createdAt', + 'tools', ], properties: { + id: { + description: 'unique note hisotry record identifier', + type: 'number', + }, + noteId: { + description: 'unique note identifier', + type: 'number', + }, + userId: { + description: 'unique user identifier', + type: 'number', + }, + createdAt: { + description: 'time, when note history record was created', + type: 'string', + format: 'date-time', + }, + content: { + description: 'content of certain version of the note', + type: 'object', + properties: { + time: { + type: 'number', + }, + blocks: { + type: 'array', + }, + version: { + type: 'string', + }, + }, + }, + tools: { + description: 'list of editor tools objects "toolName": "toolId" for content displaying', + type: 'array', + items: { + type: 'object', + properties: { + id: { + type: 'string', + }, + name: { + type: 'string', + }, + }, + }, + }, + }, +}; + +export const HistoryMetaSchema = { + $id: 'HistoryMetaSchema', + type: 'object', + required: [ + 'id', + 'userId', + 'createdAt', + ], + id: { + description: 'unique note hisotry record identifier', + type: 'number', + }, + noteId: { + description: 'unique note identifier', + type: 'number', + }, + userId: { + description: 'unique user identifier', + type: 'number', + }, + createdAt: { + description: 'time, when note history record was created', + type: 'string', + format: 'date-time', }, };