add basic repo setup, with user creation

This commit is contained in:
mrjvs
2023-10-28 16:49:02 +02:00
parent 9166c37aea
commit 94e1f9ebe1
26 changed files with 5762 additions and 374 deletions

25
src/routes/auth/manage.ts Normal file
View File

@@ -0,0 +1,25 @@
import { User, formatUser } from '@/db/models/User';
import { handle } from '@/services/handler';
import { makeRouter } from '@/services/router';
import { z } from 'zod';
const registerSchema = z.object({
name: z.string().max(500).min(1),
device: z.string().max(500).min(1),
});
export const manageAuthRouter = makeRouter((app) => {
app.post(
'/auth/register',
{ schema: { body: registerSchema } },
handle(({ em, body }) => {
const user = new User();
user.name = body.name;
em.persistAndFlush(user);
return {
user: formatUser(user),
};
}),
);
});

View File

@@ -1,7 +0,0 @@
import { FastifyPluginAsync } from 'fastify';
export const helloRouter: FastifyPluginAsync = async (app) => {
app.get('/ping', (req, res) => {
res.send('pong!');
});
};