-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from codex-team/feat/reply
chore(fastify): router handlers updated
- Loading branch information
Showing
12 changed files
with
192 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
{ | ||
"extends": [ | ||
"codex/ts" | ||
] | ||
], | ||
"rules": { | ||
"@typescript-eslint/naming-convention": [ | ||
"error", | ||
{ | ||
"selector": "property", | ||
"format": ["camelCase", "PascalCase"], | ||
"filter": { | ||
// Allow "2xx" as a property name, used in the API response schema | ||
"regex": "^(2xx)$", | ||
"match": false | ||
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { StatusCodes } from 'http-status-codes'; | ||
import type { FastifyReply } from 'fastify'; | ||
|
||
/** | ||
* Custom method for sending 404 error | ||
* | ||
* @example | ||
* | ||
* if (note === null) { | ||
* return fastify.notFound(reply, 'Note not found'); | ||
* } | ||
* | ||
* @param reply - fastify reply instance | ||
* @param message - custom message | ||
*/ | ||
export default async function notFound(reply: FastifyReply, message = 'Not found'): Promise<void> { | ||
await reply | ||
.code(StatusCodes.NOT_FOUND) | ||
.type('application/json') | ||
.send({ | ||
message, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars, no-unused-vars */ | ||
import type * as fastify from 'fastify'; | ||
import type * as http from 'http'; | ||
|
||
declare module 'fastify' { | ||
export interface FastifyInstance< | ||
HttpServer = http.Server, | ||
HttpRequest = http.IncomingMessage, | ||
HttpResponse = http.ServerResponse | ||
> { | ||
/** | ||
* Custom method for sending 404 error | ||
* | ||
* @example | ||
* | ||
* if (note === null) { | ||
* return fastify.notFound(reply, 'Note not found'); | ||
* } | ||
* | ||
* @param reply - Fastify reply object | ||
* @param message - Optional message to send. If not specified, default message will be sent | ||
*/ | ||
notFound: (reply: fastify.FastifyReply, message?: string) => Promise<void>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.