mirror of
https://github.com/movie-web/backend.git
synced 2025-09-13 18:13:26 +00:00
add basic repo setup, with user creation
This commit is contained in:
25
src/routes/auth/manage.ts
Normal file
25
src/routes/auth/manage.ts
Normal 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),
|
||||
};
|
||||
}),
|
||||
);
|
||||
});
|
@@ -1,7 +0,0 @@
|
||||
import { FastifyPluginAsync } from 'fastify';
|
||||
|
||||
export const helloRouter: FastifyPluginAsync = async (app) => {
|
||||
app.get('/ping', (req, res) => {
|
||||
res.send('pong!');
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user