This commit is contained in:
lingdocs 2021-08-22 13:53:16 +04:00
parent fbcdc7576a
commit b9df8537cd
4 changed files with 14 additions and 9 deletions

View File

@ -125,7 +125,14 @@ export async function createWordlistDatabase(uuid: T.UUID): Promise<{ name: T.Wo
export async function deleteWordlistDatabase(uuid: T.UUID): Promise<void> {
const name = getWordlistDbName(uuid);
await nano.db.destroy(name);
try {
await nano.db.destroy(name);
} catch (e) {
// allow the error to pass if we're just trying to delete a database that never existed
if (e.message !== "Database does not exist.") {
throw new Error("error deleting database");
}
}
}
function generateWordlistDbPassword(): T.UserDbPassword {

View File

@ -135,10 +135,11 @@ apiRouter.put("/user/upgrade", async (req, res, next) => {
apiRouter.delete("/user", async (req, res, next) => {
try {
if (!req.user) throw new Error("user not found");
const dUser = deleteLingdocsUser(req.user.userId);
const dDb = deleteWordlistDatabase(req.user.userId);
await Promise.all([dUser, dDb]);
sendResponse(res, { ok: true, message: "user delted" });
await Promise.all([
deleteWordlistDatabase(req.user.userId),
deleteLingdocsUser(req.user.userId),
]);
sendResponse(res, { ok: true, message: "user deleted" });
} catch (e) {
next(e);
}

View File

@ -128,7 +128,6 @@ const authRouter = (passport: PassportStatic) => {
router.post("/register", async (req, res, next) => {
try {
const { email, password, name } = req.body;
console.log(email, password, name);
const existingUser = await getLingdocsUser("email", email);
if (existingUser) return res.send("User Already Exists");
const user = await createNewUser({ strategy: "local", email, passwordPlainText: password, name });

View File

@ -16,9 +16,7 @@ async function accountApiFetch(url: string, method: "GET" | "POST" | "PUT" | "DE
body: JSON.stringify(body),
} : {},
});
const raw = await response.text();
console.log("api response:", raw);
return JSON.parse(raw) as AT.APIResponse;
return await response.json() as AT.APIResponse;
}
export async function publishDictionary(): Promise<FT.PublishDictionaryResponse> {