|
|
|
@ -24,12 +24,16 @@ router.post("/addlocal", async (req, res) => {
|
|
|
|
|
if (creds.length === 0) { |
|
|
|
|
return res.status(400).json({ |
|
|
|
|
success: false, |
|
|
|
|
message: "there's no client id or secret configured for this user", |
|
|
|
|
message: "no secrets have been configured yet!", |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const validatedNum = { |
|
|
|
|
number: value.number, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if (findExisting.length === 0) { |
|
|
|
|
const addBnums = new Bnums(num); |
|
|
|
|
const addBnums = new Bnums(validatedNum); |
|
|
|
|
addBnums.userId = creds[0].userId; |
|
|
|
|
await addBnums.save(); |
|
|
|
|
} else { |
|
|
|
@ -70,6 +74,13 @@ router.get("/getlocal", async (req, res) => {
|
|
|
|
|
userId: thetoken._id, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (creds.length === 0) { |
|
|
|
|
return res.status(400).json({ |
|
|
|
|
success: false, |
|
|
|
|
message: "no secrets have been configured yet!", |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const getNumbers = await Bnums.find({ userId: thetoken._id }); |
|
|
|
|
|
|
|
|
|
if (getNumbers.length === 0) { |
|
|
|
@ -78,10 +89,6 @@ router.get("/getlocal", async (req, res) => {
|
|
|
|
|
message: "no numbers exist in the db for this user!", |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
// throw {
|
|
|
|
|
// message: "no numbers exist in the db for this user!",
|
|
|
|
|
// };
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
res.status(200).json({ success: true, message: getNumbers }); |
|
|
|
|
} catch (err) { |
|
|
|
@ -96,6 +103,13 @@ router.get("/getremote", async (req, res) => {
|
|
|
|
|
userId: thetoken._id, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (creds.length === 0) { |
|
|
|
|
return res.status(400).json({ |
|
|
|
|
success: false, |
|
|
|
|
message: "no secrets have been configured yet!", |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
msger.CONFIG.setConfig(authConfig(creds)); |
|
|
|
|
const bnum = msger.BNUM.getInstance(); |
|
|
|
|
const getBnums = await bnum.get(); |
|
|
|
@ -112,8 +126,6 @@ router.get("/getremote", async (req, res) => {
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
console.log(getBnums); |
|
|
|
|
|
|
|
|
|
if (getBnums && getBnums.message) { |
|
|
|
|
const checkFail = getBnums.message.includes("fail"); |
|
|
|
|
if (checkFail) |
|
|
|
@ -136,6 +148,13 @@ router.get("/register", async (req, res) => {
|
|
|
|
|
userId: thetoken._id, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (creds.length === 0) { |
|
|
|
|
return res.status(400).json({ |
|
|
|
|
success: false, |
|
|
|
|
message: "no secrets have been configured yet!", |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
msger.CONFIG.setConfig(authConfig(creds)); |
|
|
|
|
const findBnums = await Bnums.find({ userId: thetoken._id }); |
|
|
|
|
|
|
|
|
@ -157,7 +176,7 @@ router.get("/register", async (req, res) => {
|
|
|
|
|
if (registeredBnums && registeredBnums.message) { |
|
|
|
|
const checkFail = registeredBnums.message.includes("fail"); |
|
|
|
|
if (checkFail) { |
|
|
|
|
throw { message: "Request failed!" }; |
|
|
|
|
throw { message: registeredBnums.message }; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|