/img (fixed)

Błędy rzucane przez multer są teraz obsługiwane poprawnie
This commit is contained in:
2020-12-09 16:41:08 +01:00
parent f2dce7b5ae
commit 609f18291c
3 changed files with 20 additions and 16 deletions

View File

@@ -19,23 +19,24 @@ const uploadStrategy = multer({
// POST
router.post("/", async (req, res) => {
try {
await uploadStrategy(req, res, async (err) => {
router.post("/", (req, res) => {
uploadStrategy(req, res, async (err) => {
if (err) {
if (err.code === "LIMIT_FILE_SIZE") {
throw newError("error", 413);
handleError(newError("File too big", 413), res);
} else {
handleError(newError("Unknown error...", 500), res);
}
} else {
try {
const token = req.headers["x-auth-token"];
validateUserToken(token);
await uploadBlob(req, res);
} catch (error) {
handleError(error, res)
}
}
})
} catch (error) {
console.log("error: " + error)
handleError(error, res);
}
});
module.exports = router;

View File

@@ -203,7 +203,7 @@ router.post("/trial", async (req, res) => {
const token = req.headers["x-auth-token"];
const user = validateUserToken(token);
await startTrial(req.body.restaurantId, user);
res.send("Trial aktywowany.");
res.send("Okres próbny aktywowany.");
} catch (error) {
handleError(error, res);
}

View File

@@ -126,7 +126,7 @@ async function startTrial(restaurantId, userData) {
throw newError("Nie udało się pobrać restauracji.", 404);
});
if (!userData.trialUsed || userData.trialUsed === false) {
const dueDate = dueDateBasedOnSubscription(restaurant, monthsToAdd);
const dueDate = dueDateBasedOnSubscription(restaurant, 3);
const start = startDate(restaurant);
await Restaurant.findByIdAndUpdate(restaurantId, {
$set: {
@@ -140,6 +140,9 @@ async function startTrial(restaurantId, userData) {
500
);
});
await User.findByIdAndUpdate(userData.id, { $set: { trialUsed: true } }).catch((e) => {
throw newError("Błąd podczas aktywacji okresu próbnego (user data)")
})
} else {
throw newError("Okres próbny został już wykorzystany.", 500);
}