Skip to content

Commit

Permalink
added note history shema
Browse files Browse the repository at this point in the history
  • Loading branch information
e11sy committed Jul 22, 2024
1 parent 463ca30 commit e5c77ec
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/presentation/http/http-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
40 changes: 40 additions & 0 deletions src/presentation/http/router/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,26 @@ const NoteRouter: FastifyPluginCallback<NoteRouterOptions> = (fastify, opts, don
'userCanEdit',
],
},
schema: {
params: {
notePublicId: {
$ref: 'NoteSchema#/properties/id',
},
},
response: {
'2xx': {
type: 'object',
properties: {
noteHistoryMeta: {
type: 'array',
items: {
$ref: 'HistoryMetaSchema#',
},
},
},
},
},
},
preHandler: [
noteResolver,
],
Expand Down Expand Up @@ -701,6 +721,26 @@ const NoteRouter: FastifyPluginCallback<NoteRouterOptions> = (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,
],
Expand Down
76 changes: 76 additions & 0 deletions src/presentation/http/schema/History.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
};

0 comments on commit e5c77ec

Please sign in to comment.