blob: 7359a688d7415d1cbc990a27bb11105d3d628a9a [file] [log] [blame]
pineafanc540da92021-09-03 20:33:36 +01001import MongoClient from 'mongodb';
2
3
4const url = 'mongodb://rsm:LJMy*orVFAATQ5PaX7EKXq74&HCDFaLE@192.168.101.2:27017/rsm';
5const db = 'rsm';
6const collection = 'rsmv-tokens'
7
8export default (req, res) => {
9 return new Promise((resolve, reject) => {
10 MongoClient.connect(url, async function(err, client) {
11 let db_response = await client.db(db).collection(collection).findOne({code: req.body.code});
12
13 if (!db_response) return resolve(res.status(404).end());
14 if (db_response.timestamp + (1800) >= Date.now()) return resolve(res.status(410));
15
16 let props = {
17 user: db_response.user,
18 role: db_response.role,
19 role_name: db_response.role_name,
20 guild: db_response.guild,
21 guild_name: db_response.guild_name,
22 guild_icon_url: db_response.guild_icon_url,
23 guild_size: db_response.guild_size
24 }
25 return resolve(res.status(200).send(props));
26 })
27 })
28}