-
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.
- Loading branch information
Showing
10 changed files
with
154 additions
and
13 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,32 @@ | ||
import { NextFunction, Request, Response } from "express"; | ||
import { validationResult } from "express-validator"; | ||
import jwt from "jsonwebtoken"; | ||
import APIError from "../exeption/APIError"; | ||
import ValidationError from "../exeption/ValidationError"; | ||
import Holding from "../models/holdings.model"; | ||
import Locals from "../providers/Locals"; | ||
|
||
class HoldingController { | ||
public getHoldings = async ( | ||
request: Request, | ||
response: Response, | ||
next: NextFunction | ||
) => { | ||
try { | ||
const errors = validationResult(request); | ||
if (!errors.isEmpty()) { | ||
throw new ValidationError(errors, 400); | ||
} | ||
const userId = request.user._id; | ||
const holdings = await Holding.find({ user: userId }).limit(50).skip(0); | ||
response.json({ | ||
message: "Holding fetched Successfully", | ||
holdings: holdings, | ||
}); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
} | ||
|
||
export default new HoldingController(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Router } from "express"; | ||
import { body } from "express-validator"; | ||
import holdingController from "../controllers/holding.controller"; | ||
const router = Router(); | ||
|
||
router.get("/", holdingController.getHoldings); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
import { Router } from "express"; | ||
import { body, param } from "express-validator"; | ||
import { currentPriceError, tickerError } from "../constants/security.contant"; | ||
import userController from "../controllers/security.controller"; | ||
import securityController from "../controllers/security.controller"; | ||
const router = Router(); | ||
|
||
router.post( | ||
"/", | ||
body("ticker", tickerError).isString().isLength({ min: 3, max: 10 }), | ||
body("totalShares").isInt({ min: 10, max: 100000 }), | ||
body("currentPrice", currentPriceError).isInt({ min: 1, max: 100000 }), | ||
userController.createSecurity | ||
body("currentPrice", currentPriceError).isFloat({ min: 1, max: 100000 }), | ||
securityController.createSecurity | ||
); | ||
|
||
router.delete( | ||
"/:ticker", | ||
param("ticker", tickerError).isString().isLength({ min: 3, max: 10 }), | ||
userController.deleteSecurity | ||
securityController.deleteSecurity | ||
); | ||
|
||
router.put( | ||
"/:ticker", | ||
param("ticker", tickerError).isString().isLength({ min: 3, max: 10 }), | ||
body("currentPrice", currentPriceError).isInt({ min: 1, max: 100000 }), | ||
userController.updateCurrentPrice | ||
body("currentPrice", currentPriceError).isFloat({ min: 1, max: 100000 }), | ||
securityController.updateCurrentPrice | ||
); | ||
|
||
router.get("/", securityController.getSecurities); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,6 @@ router.put( | |
userController.topUpUser | ||
); | ||
|
||
router.get("/", userController.getUser); | ||
|
||
export default router; |