Skip to content

Commit 64c1c16

Browse files
committed
added winston logger
1 parent 6a4d00d commit 64c1c16

File tree

16 files changed

+228
-28
lines changed

16 files changed

+228
-28
lines changed

package-lock.json

Lines changed: 177 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"reflect-metadata": "^0.2.2",
2525
"ts-jest": "^29.2.5",
2626
"typeorm": "^0.3.20",
27-
"typing-assets": "^2.1.3"
27+
"typing-assets": "^2.1.3",
28+
"winston": "^3.17.0"
2829
},
2930
"devDependencies": {
3031
"@types/bcrypt": "^5.0.2",

source/api/v1/api/handlers/common/CommonHandler.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export class CommonHandler implements Handler {
2323

2424
const result = await this.healthcheck.getFullSystemReport()
2525
if (isException(result)) {
26-
// @ts-ignore
2726
reply.code(result.statusCode).send(result)
2827
return
2928
}

source/api/v1/api/handlers/notes/NotesHandlers.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FastifyInstance } from "fastify";
22
import { INotesService } from "../../../services/notes/NotesServiceInterface";
3-
import { Note, NoteCollaborators, NotePreview, NoteUpdate, NoteWithoutMetadata } from "../../../shared/dto/NoteDto";
3+
import { NoteUpdate, NoteWithoutMetadata } from "../../../shared/dto/NoteDto";
44
import { extractJwtPayload } from "../../../shared/utils/jwt/PayloadExtractor";
55
import { extractToken } from "../../../shared/utils/common/TokenExtractor";
66
import { AddCollaboratorSchema, CreateNoteSchema, DeleteNoteSchema, GetNoteCollaboratorsSchema, GetNoteSchema, GetNotesSchema, RemoveCollaboratorSchema, UpdateNoteSchema } from "../../validation/schemas/NoteSchemas";
@@ -44,7 +44,7 @@ export class NotesHandler implements Handler {
4444
Querystring: {
4545
limit: number,
4646
offset: number,
47-
sort: "ASC" | "DESC",
47+
date_sort: "ASC" | "DESC",
4848
tags: string[]
4949
},
5050
}>("/notes/my",
@@ -57,12 +57,9 @@ export class NotesHandler implements Handler {
5757
extractToken(request)
5858
)
5959

60-
const limit = request.query.limit
61-
const skip = request.query.offset
62-
const sort = request.query.sort
63-
const tags = request.query.tags
60+
const {limit, offset, date_sort, tags} = request.query
6461

65-
const notes = await this.notesService.getMyNotes(login, {tags, limit, skip, sort})
62+
const notes = await this.notesService.getMyNotes(login, {tags, limit, offset, date_sort})
6663
if (isException(notes)) {
6764
reply.code(notes.statusCode).send(notes)
6865
return
@@ -92,7 +89,7 @@ export class NotesHandler implements Handler {
9289
const sort = request.query.sort
9390
const tags = request.query.tags
9491

95-
const notes = await this.notesService.getCollaboratedNotes(login, {tags, limit, skip, sort})
92+
const notes = await this.notesService.getCollaboratedNotes(login, {tags, limit, offset: skip, date_sort: sort})
9693
if (isException(notes)) {
9794
reply.code(notes.statusCode).send(notes)
9895
return
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FastifyReply, FastifyRequest } from "fastify"
2+
import { LOGGER } from "../../shared/utils/common/Logger"
23

34
export const logRequestMetadata = (request: FastifyRequest, _reply: FastifyReply, done: any): void => {
4-
console.log(`[${request.method}] Request from ${request.ip} with route ${request.hostname}${request.url}`)
5+
LOGGER.log('info', `[${request.method}] Request from ${request.ip} with route ${request.hostname}${request.url}`)
56
done()
67
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FastifyReply, FastifyRequest } from "fastify"
2+
import { LOGGER } from "../../shared/utils/common/Logger"
23

34
export const logResponseMetadata = (_request: FastifyRequest, reply: FastifyReply, done: any): void => {
4-
console.log(`[RESPONSE] With status: ${reply.statusCode}\n`)
5+
LOGGER.log('info', `[RESPONSE] With status: ${reply.statusCode}\n`)
56
done()
67
}

source/api/v1/api/validation/schemas/NoteSchemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const GetNotesSchema: FastifySchema = {
3232
properties: {
3333
limit: { type: 'integer', minimum: 0 },
3434
offset: { type: 'integer', minimum: 0 },
35-
sort: { type: "string", enum: ["ASC", "DESC"] },
35+
date_sort: { type: "string", enum: ["ASC", "DESC"] },
3636
tags: { type: 'array', items: { type: 'string' }, maxItems: 20 }
3737
}
3838
},

0 commit comments

Comments
 (0)