add user registration
This commit is contained in:
30
server/src/controller/users.controller.ts
Normal file
30
server/src/controller/users.controller.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { RequestHandler, Router } from 'express'
|
||||
import { UserDto } from '../dto/user.dto';
|
||||
import { UserService } from '../service/user.service';
|
||||
|
||||
const router = Router();
|
||||
|
||||
const basePath = '/users'
|
||||
|
||||
export const post: RequestHandler = (req, res) => {
|
||||
const { email, password } = req.body;
|
||||
|
||||
UserService.create({
|
||||
email,
|
||||
password
|
||||
}).then(user => {
|
||||
const respose: UserDto = {
|
||||
id: user.id,
|
||||
email: user.email
|
||||
}
|
||||
|
||||
res.json(respose);
|
||||
}).catch(err => {
|
||||
res.status(422).json({
|
||||
error: err.message
|
||||
});
|
||||
})
|
||||
}
|
||||
router.post(basePath, post)
|
||||
|
||||
export const UserRoutes = router;
|
||||
Reference in New Issue
Block a user