Updated gitignore to ignore log files, Refactored Authcontroller to use DB interface, Added Try/Catch to validation to catch uncaught error, Added username optional validation to Joi so it expects a username
This commit is contained in:
1 parent
c5b93e7437
commit
a4a61695b0
7 files changed
+137
-72
No files matched your search
@@ -1,5 +1,6 @@
|
||||
const Monitor = require("../models/Monitor");
|
||||
const mongoose = require("mongoose");
|
||||
const UserModel = require("../models/user");
|
||||
|
||||
const connect = async () => {
|
||||
try {
|
||||
@@ -11,6 +12,25 @@ const connect = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const insertUser = async (req, res) => {
|
||||
try {
|
||||
const newUser = await UserModel.create({ ...req.body });
|
||||
return newUser;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const getUserByEmail = async (req, res) => {
|
||||
try {
|
||||
// Returns null if no user is found
|
||||
const user = await UserModel.findOne({ email: req.body.email });
|
||||
return user;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Gets all monitors
|
||||
const getAllMonitors = async (req, res) => {
|
||||
try {
|
||||
@@ -43,6 +63,8 @@ const getMonitorsByUserId = async (req, res) => {
|
||||
|
||||
module.exports = {
|
||||
connect,
|
||||
insertUser,
|
||||
getUserByEmail,
|
||||
getAllMonitors,
|
||||
getMonitorById,
|
||||
getMonitorsByUserId,
|
||||
|
||||
Reference in new issue
Block a user