Skip to content

Instantly share code, notes, and snippets.

@MrBns
Created March 29, 2024 23:36
Show Gist options
  • Save MrBns/51fe583f7171fd29942fd5d5b117e499 to your computer and use it in GitHub Desktop.
Save MrBns/51fe583f7171fd29942fd5d5b117e499 to your computer and use it in GitHub Desktop.
Send Fastify Response Within ia Schema
import { FastifyReply } from "fastify";
export function valid_reply(rep: FastifyReply, data: object | null | undefined, msg = "Successful Response", status = 200) {
return rep.send({
message: msg,
success: true,
error: false,
statusCode: status,
data,
});
}
export function invalid_reply(rep: FastifyReply, data: object | null | undefined, msg = "Something Went Wrong", status = 200) {
return rep.send({
message: msg,
success: false,
error: true,
statusCode: status,
data,
});
}
export function valid_return(data: any, msg = "Successful Response", status = 200) {
return {
message: msg,
success: true,
error: false,
statusCode: status,
data,
};
}
export function invalid_return(data: any, msg = "Something Went Wrong", status = 400) {
return {
message: msg,
success: false,
error: true,
statusCode: status,
data,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment