Skip to content

Commit

Permalink
improve schemas and delete extra middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Rad1kal committed Oct 21, 2023
1 parent 57f3f62 commit 848457c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/presentation/http/router/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type NoteSettingsService from '@domain/service/noteSettings.js';
import { StatusCodes } from 'http-status-codes';
import type { ErrorResponse } from '@presentation/http/types/HttpResponse.js';
import type { Note, NotePublicId } from '@domain/entities/note.js';
import { NoteSchema, NoteEditPayloadSchema } from '../schema/Note.js';
import { GetNoteSchema, NoteEditPayloadSchema } from '../schema/Note.js';

/**
* Get note by id options
Expand Down Expand Up @@ -85,9 +85,8 @@ const NoteRouter: FastifyPluginCallback<NoteRouterOptions> = (fastify, opts, don
Params: GetNoteByIdOptions,
Reply: Note | ErrorResponse
}>('/:id', {
preHandler: opts.middlewares.withUser,
schema: {
params: NoteSchema,
params: GetNoteSchema,
},
}, async (request, reply) => {
const params = request.params;
Expand Down
33 changes: 23 additions & 10 deletions src/presentation/http/schema/Note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ export const NoteSchema = {
'maxLength': 10,
'minLength': 10,
},
},
};

export const NoteEditPayloadSchema = {
$id: 'NoteOptionSchema',
type: 'object',
properties: {
id: {
'$ref': 'NoteSchema#/properties/id',
},
'content': {
'type': 'object',
'properties': {
Expand All @@ -37,3 +27,26 @@ export const NoteEditPayloadSchema = {
},
},
};

export const GetNoteSchema = {
$id: 'GetNoteSchema',
type: 'object',
properties: {
id: {
'$ref': 'NoteSchema#/properties/id',
},
},
};

export const NoteEditPayloadSchema = {
$id: 'NoteOptionSchema',
type: 'object',
properties: {
id: {
'$ref': 'NoteSchema#/properties/id',
},
'content': {
'$ref': 'NoteSchema#/properties/content',
},
},
};

0 comments on commit 848457c

Please sign in to comment.