/img (fixed)
Błędy rzucane przez multer są teraz obsługiwane poprawnie
This commit is contained in:
@@ -19,23 +19,24 @@ const uploadStrategy = multer({
|
|||||||
|
|
||||||
// POST
|
// POST
|
||||||
|
|
||||||
router.post("/", async (req, res) => {
|
router.post("/", (req, res) => {
|
||||||
try {
|
uploadStrategy(req, res, async (err) => {
|
||||||
await uploadStrategy(req, res, async (err) => {
|
if (err) {
|
||||||
if(err){
|
if (err.code === "LIMIT_FILE_SIZE") {
|
||||||
if(err.code === "LIMIT_FILE_SIZE"){
|
handleError(newError("File too big", 413), res);
|
||||||
throw newError("error", 413);
|
} else {
|
||||||
|
handleError(newError("Unknown error...", 500), res);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const token = req.headers["x-auth-token"];
|
try {
|
||||||
validateUserToken(token);
|
const token = req.headers["x-auth-token"];
|
||||||
await uploadBlob(req, res);
|
validateUserToken(token);
|
||||||
|
await uploadBlob(req, res);
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error, res)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (error) {
|
|
||||||
console.log("error: " + error)
|
|
||||||
handleError(error, res);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
@@ -203,7 +203,7 @@ router.post("/trial", async (req, res) => {
|
|||||||
const token = req.headers["x-auth-token"];
|
const token = req.headers["x-auth-token"];
|
||||||
const user = validateUserToken(token);
|
const user = validateUserToken(token);
|
||||||
await startTrial(req.body.restaurantId, user);
|
await startTrial(req.body.restaurantId, user);
|
||||||
res.send("Trial aktywowany.");
|
res.send("Okres próbny aktywowany.");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, res);
|
handleError(error, res);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ async function startTrial(restaurantId, userData) {
|
|||||||
throw newError("Nie udało się pobrać restauracji.", 404);
|
throw newError("Nie udało się pobrać restauracji.", 404);
|
||||||
});
|
});
|
||||||
if (!userData.trialUsed || userData.trialUsed === false) {
|
if (!userData.trialUsed || userData.trialUsed === false) {
|
||||||
const dueDate = dueDateBasedOnSubscription(restaurant, monthsToAdd);
|
const dueDate = dueDateBasedOnSubscription(restaurant, 3);
|
||||||
const start = startDate(restaurant);
|
const start = startDate(restaurant);
|
||||||
await Restaurant.findByIdAndUpdate(restaurantId, {
|
await Restaurant.findByIdAndUpdate(restaurantId, {
|
||||||
$set: {
|
$set: {
|
||||||
@@ -140,6 +140,9 @@ async function startTrial(restaurantId, userData) {
|
|||||||
500
|
500
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
await User.findByIdAndUpdate(userData.id, { $set: { trialUsed: true } }).catch((e) => {
|
||||||
|
throw newError("Błąd podczas aktywacji okresu próbnego (user data)")
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
throw newError("Okres próbny został już wykorzystany.", 500);
|
throw newError("Okres próbny został już wykorzystany.", 500);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user