Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | const userService = require("../services/userService");
const authService = require("../services/authService");
const successResponse = require("../utils/successResponse");
/**
* Function to create a new user
* Method: POST
*/
exports.signup = async (req, res, next) => {
try {
const {
first_name,
last_name,
email,
password,
phone_number,
company_name,
} = req.body;
const newUser = await userService.createUser(
first_name,
last_name,
email,
phone_number,
company_name,
password,
);
const user = await newUser.toJSON();
delete user.password;
// Return success response
successResponse(res, user, "User created successfully", 201);
} catch (error) {
next(error);
}
};
/**
* Function to login user
* Method: POST
*/
exports.signin = async (req, res, next) => {
try {
const { email, password } = req.body;
const User = await authService.signin(email, password);
res.cookie("token", User.token);
// Return success response
successResponse(res, User, "User logged in successfully", 200);
} catch (error) {
next(error);
}
};
|