-
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.
Merge pull request #1 from sakshamchhimwal/issuesPage
Issues page
- Loading branch information
Showing
13 changed files
with
4,596 additions
and
1,169 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,13 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"extends": "standard-with-typescript", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
} | ||
} |
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 |
---|---|---|
|
@@ -128,4 +128,5 @@ dist | |
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
**/tmp |
Large diffs are not rendered by default.
Oops, something went wrong.
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
94 changes: 94 additions & 0 deletions
94
src/controllers/UserControllers/user.dashboard.controller.ts
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,94 @@ | ||
import { type NextFunction, type Response } from 'express' | ||
import UserModel from '../../models/user' | ||
import createHttpError from 'http-errors' | ||
import SuggestionModel from '../../models/suggestions' | ||
|
||
export const getAllSuggestions = async ( | ||
req: any, | ||
res: Response, | ||
next: NextFunction | ||
) => { | ||
const loggedInUserData = req.user | ||
try { | ||
const currUser = await UserModel.findOne({ | ||
Email: loggedInUserData.email | ||
}) | ||
if (!currUser) { | ||
next(createHttpError(403, 'Unauthorized')) | ||
return | ||
} | ||
if (currUser) { | ||
const currUserMess = currUser.Eating_Mess | ||
const currPage = req.query.page | ||
const LIMIT = 10 | ||
const paginatedSuggestions = await SuggestionModel.find({ | ||
messId: currUserMess | ||
}) | ||
.skip((currPage - 1) * LIMIT) | ||
.limit(LIMIT) | ||
.populate('userId', 'Username Image') | ||
.populate('upvotes downvotes', 'Username') | ||
.exec() | ||
if (paginatedSuggestions.length > 0) { | ||
return res.send({ | ||
suggestions: paginatedSuggestions, | ||
hasNext: paginatedSuggestions.length === LIMIT | ||
}) | ||
} | ||
return res.status(204).send({ suggestions: [], hasNext: false }) | ||
} | ||
} catch (err) { | ||
console.log(err) | ||
next(createHttpError(500, 'Internal Server Error')) | ||
} | ||
} | ||
|
||
export const voteSuggestion = async ( | ||
req: any, | ||
res: Response, | ||
next: NextFunction | ||
) => { | ||
const loggedInUserData = req.user | ||
try { | ||
const currUser = await UserModel.findOne({ | ||
Email: loggedInUserData.email | ||
}) | ||
if (!currUser) { | ||
next(createHttpError(403, 'Unauthorized')) | ||
return | ||
} | ||
const suggestionId = req.body.suggestionId | ||
const updateType = | ||
req.body.upvote === true | ||
? { | ||
$addToSet: { upvotes: currUser._id }, | ||
$pull: { downvotes: currUser._id } | ||
} | ||
: { | ||
$pull: { upvotes: currUser._id }, | ||
$addToSet: { downvotes: currUser._id } | ||
} | ||
const newVote = await SuggestionModel.findOneAndUpdate( | ||
{ | ||
_id: suggestionId | ||
}, | ||
updateType, | ||
{ new: true } | ||
) | ||
if (newVote !== null) { | ||
return res.send({ | ||
_id: newVote._id, | ||
message: 'Voted Successfully', | ||
upvotes: newVote?.upvotes, | ||
downvotes: newVote?.downvotes | ||
}) | ||
} else { | ||
return res.status(400).send({ message: 'Vote not casted' }) | ||
} | ||
} catch (err) { | ||
console.log(err) | ||
next(createHttpError(500, 'Internal Server Error')) | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.