oops
This commit is contained in:
parent
2e7defbf61
commit
3fea41977f
|
@ -91,37 +91,41 @@ apiRouter.put("/email-verification", async (req, res, next) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
apiRouter.post("/user/upgrade", async (req, res, next) => {
|
apiRouter.put("/user/upgrade", async (req, res, next) => {
|
||||||
if (!req.user) throw new Error("user not found");
|
if (!req.user) throw new Error("user not found");
|
||||||
const givenPassword = (req.body.password || "") as string;
|
try {
|
||||||
const studentPassword = env.upgradePassword;
|
const givenPassword = (req.body.password || "") as string;
|
||||||
if (givenPassword.toLowerCase().trim() !== studentPassword.toLowerCase()) {
|
const studentPassword = env.upgradePassword;
|
||||||
const wrongPass: T.UpgradeUserResponse = {
|
if (givenPassword.toLowerCase().trim() !== studentPassword.toLowerCase()) {
|
||||||
ok: false,
|
const wrongPass: T.UpgradeUserResponse = {
|
||||||
error: "incorrect password",
|
ok: false,
|
||||||
};
|
error: "incorrect password",
|
||||||
res.send(wrongPass);
|
};
|
||||||
return;
|
res.send(wrongPass);
|
||||||
}
|
return;
|
||||||
const { userId } = req.user;
|
}
|
||||||
const user = await getLingdocsUser("userId", userId);
|
const { userId } = req.user;
|
||||||
if (user) {
|
const user = await getLingdocsUser("userId", userId);
|
||||||
const alreadyUpgraded: T.UpgradeUserResponse = {
|
if (user) {
|
||||||
|
const alreadyUpgraded: T.UpgradeUserResponse = {
|
||||||
|
ok: true,
|
||||||
|
message: "user already upgraded",
|
||||||
|
user,
|
||||||
|
};
|
||||||
|
res.send(alreadyUpgraded);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { name, password } = await createWordlistDatabase(userId);
|
||||||
|
const u = await updateLingdocsUser(userId, { level: "student", wordlistDbName: name, userDbPassword: password });
|
||||||
|
const upgraded: T.UpgradeUserResponse = {
|
||||||
ok: true,
|
ok: true,
|
||||||
message: "user already upgraded",
|
message: "user upgraded to student",
|
||||||
user,
|
user: u,
|
||||||
};
|
};
|
||||||
res.send(alreadyUpgraded);
|
res.send(upgraded);
|
||||||
return;
|
} catch (e) {
|
||||||
|
next(e);
|
||||||
}
|
}
|
||||||
const { name, password } = await createWordlistDatabase(userId);
|
|
||||||
const u = await updateLingdocsUser(userId, { level: "student", wordlistDbName: name, userDbPassword: password });
|
|
||||||
const upgraded: T.UpgradeUserResponse = {
|
|
||||||
ok: true,
|
|
||||||
message: "user upgraded to student",
|
|
||||||
user: u,
|
|
||||||
};
|
|
||||||
res.send(upgraded);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue