Created
March 29, 2024 23:36
-
-
Save MrBns/51fe583f7171fd29942fd5d5b117e499 to your computer and use it in GitHub Desktop.
Send Fastify Response Within ia Schema
This file contains hidden or 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
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