-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backend changes for implement user dashboard
- Loading branch information
Showing
6 changed files
with
66 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import express from "express" | ||
import SkinProfile from "../models/SkinProfile" | ||
import authenticate from "../middleware/authenticate" | ||
|
||
const router = express.Router() | ||
|
||
// TODO: implement | ||
// router.get( | ||
// "/", | ||
// authenticate, | ||
// async (req: express.Request, res: express.Response) => { | ||
// const { user } = req.body | ||
// console.log(user) | ||
// res.status(200).send({ | ||
// name: user.name, | ||
// email: user.email, | ||
// skinProfile: user.skin_profile ?? null, | ||
// }) | ||
// } | ||
// ) | ||
|
||
router.post("/", authenticate, async (req, res) => { | ||
Check failure Code scanning / CodeQL Missing rate limiting High
This route handler performs
authorization Error loading related location Loading |
||
const { type, concerns, prevRoutine, complexity, budget, user } = req.body | ||
|
||
if (!type || !concerns || !prevRoutine || !complexity || !budget) { | ||
return res.status(400).json({ | ||
error: | ||
"Invalid request body. Must contain type, concerns, prevRoutine, complexity and budget.", | ||
}) | ||
} | ||
|
||
const profile = new SkinProfile({ | ||
type: type, | ||
concerns: concerns, | ||
prevRoutine: prevRoutine, | ||
complexity: complexity, | ||
budget: budget, | ||
}) | ||
|
||
try { | ||
const filter = { _id: user._id } | ||
const userCollection = req.app.locals.db.collection("user") | ||
await userCollection.updateOne( | ||
filter, | ||
{ $set: { skin_profile: profile } }, | ||
(err: Error) => { | ||
if (err) throw err | ||
console.log("1 document updated") | ||
} | ||
) | ||
|
||
return res.status(200).json({ success: "New skin profile added" }) | ||
} catch (err: any) { | ||
console.error(err.message) | ||
return res.status(500).json({ error: "Server error. Please try again" }) | ||
} | ||
}) | ||
|
||
export default router | ||
|
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
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
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
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
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