1
1
import { FastifyInstance } from "fastify" ;
2
- import { INotesService } from "../services/notes/NotesServiceInterface" ;
3
- import { Note , NoteCollaborators , NotePreview , NoteUpdate , NoteWithoutMetadata } from "../database/entities/Note" ;
4
- import { NOTE_EXCEPTIONS } from "../shared/exceptions/NoteExceptions" ;
5
- import { extractJwtPayload } from "../auth/jwt/PayloadExtractor" ;
6
- import { extractToken } from "../shared/utils/common/TokenExtractor" ;
7
- import { AddCollaboratorSchema , CreateNoteSchema , DeleteNoteSchema , GetNoteCollaboratorsSchema , GetNoteSchema , GetNotesSchema , RemoveCollaboratorSchema , UpdateNoteSchema } from "../validation/schemas/NoteSchemas" ;
8
- import { isException } from "../shared/utils/guards/ExceptionGuard" ;
9
- import { USER_EXCEPTIONS } from "../shared/exceptions/UserExceptions" ;
10
- import { Handler } from "./Handler" ;
11
- import { AuthentificationPreHandler } from "../auth/AuthPreHandler" ;
2
+ import { INotesService } from "../../../services/notes/NotesServiceInterface" ;
3
+ import { Note , NoteCollaborators , NotePreview , NoteUpdate , NoteWithoutMetadata } from "../../../shared/dto/NoteDto" ;
4
+ import { extractJwtPayload } from "../../../shared/utils/jwt/PayloadExtractor" ;
5
+ import { extractToken } from "../../../shared/utils/common/TokenExtractor" ;
6
+ import { AddCollaboratorSchema , CreateNoteSchema , DeleteNoteSchema , GetNoteCollaboratorsSchema , GetNoteSchema , GetNotesSchema , RemoveCollaboratorSchema , UpdateNoteSchema } from "../../validation/schemas/NoteSchemas" ;
7
+ import { isException } from "../../../shared/utils/guards/ExceptionGuard" ;
8
+ import { Handler } from "../Handler" ;
9
+ import { AuthorizationPreHandler } from "../../prehandlers/AuthPreHandler" ;
12
10
13
11
export class NotesHandler extends Handler < INotesService > {
14
12
constructor (
15
13
server : FastifyInstance ,
16
- authentificationPreHandler : AuthentificationPreHandler ,
14
+ authorizationPreHandler : AuthorizationPreHandler ,
17
15
notesService : INotesService
18
16
) {
19
- super ( server , authentificationPreHandler , notesService )
17
+ super ( server , authorizationPreHandler , notesService )
20
18
}
21
19
22
20
public override handleRoutes ( ) : void {
23
21
this . server . post < {
24
22
Body : Omit < NoteWithoutMetadata , "author" > ,
25
- Reply : {
26
- 201 : Note ,
27
- 503 : typeof NOTE_EXCEPTIONS . ServiceUnavailable | typeof USER_EXCEPTIONS . ServiceUnavailable
28
- 404 : typeof NOTE_EXCEPTIONS . CollaboratorNotFound
29
- }
30
23
} > ( "/notes" , {
31
24
schema : CreateNoteSchema ,
32
25
preHandler : this . authentificationPreHandler
@@ -56,10 +49,6 @@ export class NotesHandler extends Handler<INotesService> {
56
49
sort : "ASC" | "DESC" ,
57
50
tags : string [ ]
58
51
} ,
59
- Reply : {
60
- 200 : NotePreview [ ] ,
61
- 503 : typeof NOTE_EXCEPTIONS . ServiceUnavailable
62
- }
63
52
} > ( "/notes/my" ,
64
53
{
65
54
schema : GetNotesSchema ,
@@ -92,10 +81,6 @@ export class NotesHandler extends Handler<INotesService> {
92
81
sort : "ASC" | "DESC" ,
93
82
tags : string [ ]
94
83
} ,
95
- Reply : {
96
- 200 : NotePreview [ ] ,
97
- 503 : typeof NOTE_EXCEPTIONS . ServiceUnavailable
98
- }
99
84
} > ( "/notes/collaborated" , {
100
85
schema : GetNotesSchema ,
101
86
preHandler : this . authentificationPreHandler
@@ -119,11 +104,6 @@ export class NotesHandler extends Handler<INotesService> {
119
104
120
105
this . server . get < {
121
106
Params : { id : string } ,
122
- Reply : {
123
- 200 : Note ,
124
- 404 : typeof NOTE_EXCEPTIONS . NoteNotFound ,
125
- 503 : typeof NOTE_EXCEPTIONS . ServiceUnavailable
126
- }
127
107
} > ( "/notes/:id" ,
128
108
{
129
109
schema : GetNoteSchema ,
@@ -147,11 +127,6 @@ export class NotesHandler extends Handler<INotesService> {
147
127
148
128
this . server . delete < {
149
129
Params : { id : string } ,
150
- Reply : {
151
- 200 : { success : true } ,
152
- 404 : typeof NOTE_EXCEPTIONS . NoteNotFound ,
153
- 503 : typeof NOTE_EXCEPTIONS . ServiceUnavailable
154
- }
155
130
} > ( "/notes/:id" ,
156
131
{
157
132
schema : DeleteNoteSchema ,
@@ -175,11 +150,6 @@ export class NotesHandler extends Handler<INotesService> {
175
150
176
151
this . server . patch < {
177
152
Params : { id : string } ,
178
- Reply : {
179
- 200 : Note ,
180
- 404 : typeof NOTE_EXCEPTIONS . NoteNotFound ,
181
- 503 : typeof NOTE_EXCEPTIONS . ServiceUnavailable
182
- } ,
183
153
Body : NoteUpdate
184
154
} > ( "/notes/:id" , {
185
155
schema : UpdateNoteSchema ,
@@ -204,11 +174,6 @@ export class NotesHandler extends Handler<INotesService> {
204
174
205
175
this . server . get < {
206
176
Params : { id : string } ,
207
- Reply : {
208
- 200 : NoteCollaborators
209
- 404 : typeof NOTE_EXCEPTIONS . NoteNotFound
210
- 503 : typeof NOTE_EXCEPTIONS . ServiceUnavailable
211
- }
212
177
} > ( "/notes/:id/collaborators" , {
213
178
schema : GetNoteCollaboratorsSchema ,
214
179
preHandler : this . authentificationPreHandler
@@ -233,13 +198,6 @@ export class NotesHandler extends Handler<INotesService> {
233
198
Body : {
234
199
collaboratorLogin : string
235
200
} ,
236
- Reply : {
237
- 201 : { success : true }
238
- 503 : typeof NOTE_EXCEPTIONS . ServiceUnavailable ,
239
- 404 : typeof NOTE_EXCEPTIONS . CollaboratorNotFound | typeof NOTE_EXCEPTIONS . NoteNotFound
240
- 400 : typeof NOTE_EXCEPTIONS . CollaboratorAlreadyInNote
241
- 403 : typeof NOTE_EXCEPTIONS . AcessRestricted
242
- }
243
201
} > ( "/notes/:id/collaborators" , {
244
202
schema : AddCollaboratorSchema ,
245
203
preHandler : this . authentificationPreHandler
@@ -269,12 +227,6 @@ export class NotesHandler extends Handler<INotesService> {
269
227
Body : {
270
228
collaboratorLogin : string
271
229
} ,
272
- Reply : {
273
- 200 : { success : true }
274
- 503 : typeof NOTE_EXCEPTIONS . ServiceUnavailable
275
- 404 : typeof NOTE_EXCEPTIONS . CollaboratorNotFound | typeof NOTE_EXCEPTIONS . NoteNotFound
276
- 403 : typeof NOTE_EXCEPTIONS . AcessRestricted
277
- }
278
230
} > ( "/notes/:id/collaborators" , {
279
231
schema : RemoveCollaboratorSchema ,
280
232
preHandler : this . authentificationPreHandler
0 commit comments