const getUserRoute = createRoute({
method: 'get',
path: '/',
responses: {
200: {
description: 'Respond after getting his user',
content: {
'application/json': {
schema: schema: z.object({
id: z.string(),
email: z.string(),
username: z.string(),
createdAt: z.coerce.date(),
lastLoginOn: z.coerce.date(),
}),
},
},
},
404: {
description: 'User not found',
content: {
'application/json': {
schema: ErrorSchema,
},
},
},
},
});
app.openapi(getUserRoute, async (c) => {
const id = c.get('id');
const user = await getUser({ id });
if (user) {
return c.json({
id: user.id,
email: user.email,
username: user.username,
createdAt: user.createdAt,
lastLoginOn: user.lastLoginOn,
});
}
return c.json({
error: 'User not found',
}, 404);
const getUserRoute = createRoute({
method: 'get',
path: '/',
responses: {
200: {
description: 'Respond after getting his user',
content: {
'application/json': {
schema: schema: z.object({
id: z.string(),
email: z.string(),
username: z.string(),
createdAt: z.coerce.date(),
lastLoginOn: z.coerce.date(),
}),
},
},
},
404: {
description: 'User not found',
content: {
'application/json': {
schema: ErrorSchema,
},
},
},
},
});
app.openapi(getUserRoute, async (c) => {
const id = c.get('id');
const user = await getUser({ id });
if (user) {
return c.json({
id: user.id,
email: user.email,
username: user.username,
createdAt: user.createdAt,
lastLoginOn: user.lastLoginOn,
});
}
return c.json({
error: 'User not found',
}, 404);