11import { FastifyInstance , FastifyReply , FastifyRequest , HookHandlerDoneFunction } from "fastify" ;
2- import { INotesService } from "../services/notes /NotesServiceInterface" ;
2+ import { INotesService } from "../services/interfaces /NotesServiceInterface" ;
33import { Note , NoteCollaborators , NotePreview , NoteUpdate , NoteWithoutMetadata } from "../database/entities/Note" ;
44import { NOTE_EXCEPTIONS } from "../exceptions/NoteExceptions" ;
55import { extractJwtPayload } from "../auth/jwt/PayloadExtractor" ;
6- import { extractToken } from "../utils/TokenExtractor" ;
6+ import { extractToken } from "../utils/common/ TokenExtractor" ;
77import { AddCollaboratorSchema , CreateNoteSchema , DeleteNoteSchema , GetNoteCollaboratorsSchema , GetNoteSchema , GetNotesSchema , RemoveCollaboratorSchema , UpdateNoteSchema } from "../validation/schemas/NoteSchemas" ;
88import { isException } from "../utils/guards/ExceptionGuard" ;
99import { USER_EXCEPTIONS } from "../exceptions/UserExceptions" ;
@@ -29,13 +29,13 @@ export const handleNoteRoutes = (
2929 schema : CreateNoteSchema ,
3030 preHandler : authenticate
3131 } , async ( request , reply ) => {
32- const payload = extractJwtPayload (
32+ const { login } = extractJwtPayload (
3333 extractToken ( request )
3434 )
3535
3636 const insertData = {
3737 ...request . body ,
38- author : payload . login
38+ author : login
3939 }
4040 const createdNote = await notesService . createNote ( insertData )
4141 if ( isException ( createdNote ) ) {
@@ -64,7 +64,7 @@ export const handleNoteRoutes = (
6464 preHandler : authenticate
6565 } ,
6666 async ( request , reply ) => {
67- const payload = extractJwtPayload (
67+ const { login } = extractJwtPayload (
6868 extractToken ( request )
6969 )
7070
@@ -73,7 +73,7 @@ export const handleNoteRoutes = (
7373 const sort = request . query . sort
7474 const tags = request . query . tags
7575
76- const notes = await notesService . getMyNotes ( payload . login , tags , limit , skip , sort )
76+ const notes = await notesService . getMyNotes ( login , tags , limit , skip , sort )
7777 if ( isException ( notes ) ) {
7878 reply . code ( notes . statusCode ) . send ( notes )
7979 return
@@ -98,7 +98,7 @@ export const handleNoteRoutes = (
9898 schema : GetNotesSchema ,
9999 preHandler : authenticate
100100 } , async ( request , reply ) => {
101- const payload = extractJwtPayload (
101+ const { login } = extractJwtPayload (
102102 extractToken ( request )
103103 )
104104
@@ -107,7 +107,7 @@ export const handleNoteRoutes = (
107107 const sort = request . query . sort
108108 const tags = request . query . tags
109109
110- const notes = await notesService . getCollaboratedNotes ( payload . login , tags , limit , skip , sort )
110+ const notes = await notesService . getCollaboratedNotes ( login , tags , limit , skip , sort )
111111 if ( isException ( notes ) ) {
112112 reply . code ( notes . statusCode ) . send ( notes )
113113 return
@@ -128,13 +128,13 @@ export const handleNoteRoutes = (
128128 preHandler : authenticate
129129 } ,
130130 async ( request , reply ) => {
131- const payload = extractJwtPayload (
131+ const { login } = extractJwtPayload (
132132 extractToken ( request )
133133 )
134134
135135 const id = request . params . id
136136
137- const foundNote = await notesService . getNote ( id , payload . login )
137+ const foundNote = await notesService . getNote ( id , login )
138138 if ( isException ( foundNote ) ) {
139139 reply . code ( foundNote . statusCode ) . send ( foundNote )
140140 return
@@ -156,13 +156,13 @@ export const handleNoteRoutes = (
156156 preHandler : authenticate
157157 } ,
158158 async ( request , reply ) => {
159- const payload = extractJwtPayload (
159+ const { login } = extractJwtPayload (
160160 extractToken ( request )
161161 )
162162
163163 const id = request . params . id
164164
165- const state = await notesService . deleteNote ( id , payload . login )
165+ const state = await notesService . deleteNote ( id , login )
166166 if ( isException ( state ) ) {
167167 reply . code ( state . statusCode ) . send ( state )
168168 return
@@ -183,14 +183,14 @@ export const handleNoteRoutes = (
183183 schema : UpdateNoteSchema ,
184184 preHandler : authenticate
185185 } , async ( request , reply ) => {
186- const payload = extractJwtPayload (
186+ const { login } = extractJwtPayload (
187187 extractToken ( request )
188188 )
189189
190190 const id = request . params . id
191191 const updateData = request . body
192192
193- const updatedNote = await notesService . updateNote ( id , payload . login , updateData )
193+ const updatedNote = await notesService . updateNote ( id , login , updateData )
194194 if ( isException ( updatedNote ) ) {
195195 reply . code ( updatedNote . statusCode ) . send ( updatedNote )
196196 return
@@ -211,11 +211,13 @@ export const handleNoteRoutes = (
211211 schema : GetNoteCollaboratorsSchema ,
212212 preHandler : authenticate
213213 } , async ( request , reply ) => {
214- const payload = extractJwtPayload (
214+ const { login } = extractJwtPayload (
215215 extractToken ( request )
216216 )
217+
217218 const id = request . params . id
218- const collaborators = await notesService . getCollaborators ( id , payload . login )
219+
220+ const collaborators = await notesService . getCollaborators ( id , login )
219221 if ( isException ( collaborators ) ) {
220222 reply . code ( collaborators . statusCode ) . send ( collaborators )
221223 return
@@ -240,7 +242,7 @@ export const handleNoteRoutes = (
240242 schema : AddCollaboratorSchema ,
241243 preHandler : authenticate
242244 } , async ( request , reply ) => {
243- const payload = extractJwtPayload (
245+ const { login } = extractJwtPayload (
244246 extractToken ( request )
245247 )
246248
@@ -249,7 +251,7 @@ export const handleNoteRoutes = (
249251
250252 const state = await notesService . addCollaborator (
251253 id ,
252- payload . login ,
254+ login ,
253255 collaboratorLogin
254256 )
255257 if ( isException ( state ) ) {
@@ -275,7 +277,7 @@ export const handleNoteRoutes = (
275277 schema : RemoveCollaboratorSchema ,
276278 preHandler : authenticate
277279 } , async ( request , reply ) => {
278- const payload = extractJwtPayload (
280+ const { login } = extractJwtPayload (
279281 extractToken ( request )
280282 )
281283
@@ -284,7 +286,7 @@ export const handleNoteRoutes = (
284286
285287 const state = await notesService . removeCollaborator (
286288 id ,
287- payload . login ,
289+ login ,
288290 collaboratorLogin
289291 )
290292 if ( isException ( state ) ) {
0 commit comments