I'm new to Fastify and I've encountered a problem with accessing values in the body using Typescript. Does anyone have any ideas or suggestions? Thanks!
Update: I want to simplify my code and avoid using app.get(...)
Here's my code snippet:
App.ts
const buildServer = (options = {}) => {
const app = fastify(options);
app.register(routesApiV1, { prefix: '/api'});
return app;
}
Routes.ts
const routesApiV1: FastifyPluginCallback = (fastify, options, done) => {
fastify.route(userRoute);
done();
}
User.ts
const handler: RouteHandlerMethod = async (req, res) => {
const {
name,
lastName,
dateOfBirth,
addressLine,
zipCode,
city,
country
} = req.body; // Property '...' does not exist on type 'unknown'
...
}
const route: RouteOptions = {
method: 'GET',
url: '/user/:id',
// schema: fastifySchema, Tried but not working
handler,
preValidation,
}