-
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.
Merge pull request #55 from cd-sigma/main
build
- Loading branch information
Showing
19 changed files
with
593 additions
and
21 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
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,74 @@ | ||
const mongoLib = require("../../lib/mongo.lib"); | ||
const responseLib = require("../../lib/response.lib"); | ||
const validatorUtil = require("../../util/validators.util"); | ||
|
||
const userModel = require("../../model/user.model"); | ||
const alertTypeEnum = require("../../enum/alert.type.enum"); | ||
const resStatusEnum = require("../../enum/res.status.enum"); | ||
|
||
async function subscribeToEmail(req, res) { | ||
try { | ||
const {email} = req.body; | ||
let {id: address} = req.user.payload; | ||
address = address.toLowerCase(); | ||
|
||
if (validatorUtil.isEmpty(email)) { | ||
return responseLib.sendResponse(res, null, "email is required", resStatusEnum.VALIDATION_ERROR); | ||
} | ||
|
||
await mongoLib.findOneAndUpdate(userModel, {address: address}, { | ||
$addToSet: {alertPreferences: alertTypeEnum.EMAIL}, email: email | ||
}); | ||
|
||
return responseLib.sendResponse(res, "Subscribed to email successfully!", null, resStatusEnum.SUCCESS); | ||
} catch (error) { | ||
return responseLib.sendResponse(res, null, error, resStatusEnum.INTERNAL_SERVER_ERROR) | ||
} | ||
} | ||
|
||
async function subscribeToSlack(req, res) { | ||
try { | ||
const {webhook} = req.body; | ||
let {id: address} = req.user.payload; | ||
address = address.toLowerCase(); | ||
|
||
if (validatorUtil.isEmpty(webhook)) { | ||
return responseLib.sendResponse(res, null, "webhook is required", resStatusEnum.VALIDATION_ERROR); | ||
} | ||
|
||
await mongoLib.findOneAndUpdate(userModel, {address: address}, { | ||
$addToSet: {alertPreferences: alertTypeEnum.SLACK}, slackWebhook: webhook | ||
}); | ||
|
||
return responseLib.sendResponse(res, "Subscribed to slack successfully!", null, resStatusEnum.SUCCESS); | ||
} catch (error) { | ||
return responseLib.sendResponse(res, null, error, resStatusEnum.INTERNAL_SERVER_ERROR) | ||
} | ||
} | ||
|
||
async function subscribeToDiscord(req, res) { | ||
try { | ||
const {webhook} = req.body; | ||
let {id: address} = req.user.payload; | ||
address = address.toLowerCase(); | ||
|
||
if (validatorUtil.isEmpty(webhook)) { | ||
return responseLib.sendResponse(res, null, "webhook is required", resStatusEnum.VALIDATION_ERROR); | ||
} | ||
|
||
await mongoLib.findOneAndUpdate(userModel, {address: address}, { | ||
$addToSet: {alertPreferences: alertTypeEnum.DISCORD}, discordWebhook: webhook | ||
}); | ||
|
||
return responseLib.sendResponse(res, "Subscribed to discord successfully!", null, resStatusEnum.SUCCESS); | ||
} catch (error) { | ||
return responseLib.sendResponse(res, null, error, resStatusEnum.INTERNAL_SERVER_ERROR) | ||
|
||
} | ||
} | ||
|
||
module.exports = { | ||
subscribeToDiscord: subscribeToDiscord, | ||
subscribeToSlack: subscribeToSlack, | ||
subscribeToEmail: subscribeToEmail | ||
} |
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,11 @@ | ||
const express = require("express") | ||
const router = express.Router() | ||
|
||
const alertController = require("../controllers/alert.controller") | ||
const authMiddleware = require("../../middleware/jwt.auth.middleware") | ||
|
||
router.post("/discord/subscribe", authMiddleware.isLoggedIn, alertController.subscribeToDiscord); | ||
router.post("/slack/subscribe", authMiddleware.isLoggedIn, alertController.subscribeToSlack); | ||
router.post("/email/subscribe", authMiddleware.isLoggedIn, alertController.subscribeToEmail); | ||
|
||
module.exports = 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const jwt = require("jsonwebtoken") | ||
const validatorUtil = require("../util/validators.util") | ||
const errorUtil = require("../util/error.util") | ||
|
||
async function isLoggedIn(req, res, next) { | ||
try { | ||
if ( | ||
validatorUtil.isEmpty(req.headers.authorization) | ||
) { | ||
errorUtil.throwErr("validation exception for req.headers.authorization") | ||
} | ||
let token= req.headers.authorization.split(" ")[1]; | ||
req.user = await jwt.verify(token, process.env.JWT_SECRET) | ||
next() | ||
} catch (e) { | ||
next(e) | ||
} | ||
} | ||
|
||
module.exports = {isLoggedIn: isLoggedIn} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import axios from "axios"; | ||
|
||
const token = localStorage.getItem("token") || ""; | ||
axios.defaults.headers.post["Authorization"] = `Bearer ${token}`; | ||
|
||
let userAxios = axios.create({ | ||
baseURL: "https://finsafe-backend.insidefi.io/user/" | ||
}) | ||
|
||
let tokenAxios = axios.create({ | ||
baseURL: "https://finsafe-backend.insidefi.io/token/" | ||
}); | ||
|
||
export { userAxios, tokenAxios }; |
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,24 @@ | ||
import { userAxios, tokenAxios } from "./axios.instance"; | ||
|
||
export const getPortfolioDetails = async (address) => { | ||
try { | ||
const response = await userAxios.get(address); | ||
const { result } = response.data; | ||
const { data } = result; | ||
return data; | ||
} catch (err) { | ||
console.log(`Error occured while fetching portfolio details`, err); | ||
} | ||
}; | ||
|
||
export const getTokenDetails = async (token) => { | ||
try { | ||
const response = await tokenAxios.get(token); | ||
const { result } = response.data; | ||
const { data } = result; | ||
const { logoURI, price } = data; | ||
return { logoURI: logoURI, price: price }; | ||
} catch (err) { | ||
console.log(`Error occured while fetching token details`, err); | ||
} | ||
}; |
Oops, something went wrong.