-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Node: Adding base controllers
- Loading branch information
Showing
2 changed files
with
20 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,22 @@ | ||
import { User } from "../models/user.model.js" | ||
|
||
import bcrypt from "bcrypt"; | ||
// import { User } from "../models/user.model.js" | ||
import consola from "consola" | ||
|
||
export const signupUser = async (req, res) => { | ||
consola.info("Letsssss Code this 💪🏻"); | ||
} | ||
|
||
export const getUser = async (req, res) => { | ||
consola.info("Letsssss Code this 💪🏻"); | ||
} | ||
|
||
try { | ||
const { username, email, password } = req.body; | ||
|
||
const existedUser = await User.findOne({ | ||
$or: [{ email }, { username }] | ||
}) | ||
|
||
if (existedUser) { | ||
return res.status(400).json({ status: false, message: "User already existed" }) | ||
} | ||
|
||
const hashpassword = await bcrypt.hash(password, 10) | ||
|
||
const newUser = await User.create({ | ||
username, | ||
password: hashpassword, | ||
}) | ||
|
||
await newUser.save() | ||
export const loginUser = async (req, res) => { | ||
consola.info("Letsssss Code this 💪🏻"); | ||
} | ||
|
||
return res.status(200).json({ | ||
status: true, | ||
newUser, | ||
message: "User SignIn Successfully" | ||
}) | ||
export const updateUser = async (req, res) => { | ||
consola.info("Letsssss Code this 💪🏻"); | ||
} | ||
|
||
} catch (e) { | ||
res.status(500).json({ status: false, e, message: "Internal sever Errors" }) | ||
} | ||
export const deleteUser = async (req, res) => { | ||
consola.info("Letsssss Code this 💪🏻"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { Router } from "express"; | ||
import { signupUser } from "../controllers/user.controller.js"; | ||
import { signupUser, getUser, loginUser, updateUser, deleteUser } from "../controllers/user.controller.js"; | ||
|
||
const router = Router(); | ||
|
||
// router.get("/:username", getUser); | ||
// router.post("/login", loginUser); | ||
router.get("/:username", getUser); | ||
router.post("/login", loginUser); | ||
router.post("/signup", signupUser); | ||
// router.patch("/update", updateUser); | ||
// router.delete("/logout", deleteUser) | ||
router.patch("/update", updateUser); | ||
router.delete("/logout", deleteUser) | ||
|
||
export default router |