-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathcheckCanGenerateDiscordLink.ts
More file actions
28 lines (21 loc) · 1020 Bytes
/
checkCanGenerateDiscordLink.ts
File metadata and controls
28 lines (21 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { NextFunction } from "express";
import { CustomRequest, CustomResponse } from "../types/global";
const checkCanGenerateDiscordLink = async (req: CustomRequest, res: CustomResponse, next: NextFunction) => {
const { discordId, roles, id: userId, profileStatus } = req.userData;
const isSuperUser = roles.super_user;
const userIdInQuery = req.query.userId;
if (userIdInQuery && userIdInQuery !== userId && !isSuperUser) {
return res.boom.forbidden("User should be super user to generate link for other users");
}
if (discordId) {
return res.boom.forbidden("Only users who have never joined discord can generate invite link");
}
if (roles.archived) {
return res.boom.forbidden("Archived users cannot generate invite");
}
if (!roles.maven && !roles.designer && !roles.product_manager && profileStatus !== "VERIFIED") {
return res.boom.forbidden("Only selected roles can generate discord link directly");
}
return next();
};
module.exports = checkCanGenerateDiscordLink;