brf/server/routes/api/users.ts

44 lines
910 B
TypeScript

import * as z from 'zod'
import type { FastifyPluginCallbackZod } from 'fastify-type-provider-zod'
import { UserSchema } from '../../schemas/db.ts'
const usersPlugin: FastifyPluginCallbackZod = (fastify, _options, done) => {
const { db } = fastify
fastify.addHook('onRequest', fastify.auth)
fastify.route({
url: '/',
method: 'GET',
schema: {
response: {
200: z.array(UserSchema.omit({ password: true })),
},
},
handler() {
return db
.selectFrom('user')
.select([
'id',
'email',
'lastLoginAt',
'loginAttempts',
'lastLoginAttemptAt',
'lastActivityAt',
'bannedAt',
'bannedById',
'blockedAt',
'blockedById',
'emailVerifiedAt',
'createdAt',
])
.execute()
},
})
done()
}
export default usersPlugin