-
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
1 parent
cbd2856
commit 250a4cb
Showing
7 changed files
with
67 additions
and
157 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,5 +1,24 @@ | ||
import jwt from "jsonwebtoken"; | ||
|
||
export function jsonify(obj) { | ||
return JSON.stringify(obj, (key, value) => | ||
typeof value === "bigint" ? Number(value) : value | ||
); | ||
} | ||
|
||
export function authenticateToken(req, res, next) { | ||
const authHeader = req.headers["authorization"]; | ||
const token = authHeader && authHeader.split(" ")[1]; | ||
|
||
if (token == null) return res.sendStatus(401); | ||
|
||
jwt.verify(token, process.env.TOKEN as string, (err: any, user: any) => { | ||
console.log(err); | ||
|
||
if (err) return res.sendStatus(403); | ||
|
||
req.user = user; | ||
|
||
next(); | ||
}); | ||
} |
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,39 @@ | ||
import { jsonify, authenticateToken } from "./Helpers"; | ||
|
||
export function memberEndPoints(app) { | ||
app.post("/profile", authenticateToken, function (req, res) { | ||
res.send(jsonify(req.user)); | ||
}); | ||
|
||
//getLibrary for user | ||
app.post("/library", authenticateToken, function (req, res) { | ||
let user = req.user; | ||
global.client.prisma.rewardItem | ||
.findMany({ | ||
where: { | ||
RedeemedBy: user.id, | ||
}, | ||
select: { | ||
RewardItemID: true, | ||
RedemptionTimeStamp: true, | ||
Reward: { | ||
select: { | ||
Title: true, | ||
}, | ||
}, | ||
RedemptionText: true, | ||
}, | ||
}) | ||
.then((rawLibrary) => { | ||
let library = rawLibrary.map((item) => { | ||
return { | ||
game: item.Reward.Title, | ||
orderId: item.RewardItemID, | ||
redemptionText: item.RedemptionText, | ||
timestamp: item.RedemptionTimeStamp, | ||
}; | ||
}); | ||
return res.send(jsonify(library)); | ||
}); | ||
}); | ||
} |
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,6 +1,6 @@ | ||
export class LibraryItem { | ||
public orderId: string; | ||
public game: string; | ||
public timestamp: string; | ||
public redemptionText: string; | ||
export interface LibraryItem { | ||
orderId: string; | ||
game: string; | ||
timestamp: string; | ||
redemptionText: string; | ||
} |
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
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