Trial activation, setRestaurantVisibility, Readme update, image upload fix

This commit is contained in:
2020-11-12 16:51:13 +01:00
parent cc72671911
commit 8830303fb4
5 changed files with 87 additions and 8 deletions

View File

@@ -121,6 +121,30 @@ async function renewSubscription(restaurantId, monthsToAdd) {
return dueDateBasedOnSubscription(restaurant, monthsToAdd);
}
async function startTrial(restaurantId, userData) {
const restaurant = await Restaurant.findById(restaurantId).catch((err) => {
throw newError("Nie udało się pobrać restauracji.", 404);
});
if (!userData.trialUsed || userData.trialUsed === false) {
const dueDate = dueDateBasedOnSubscription(restaurant, monthsToAdd);
const start = startDate(restaurant);
await Restaurant.findByIdAndUpdate(restaurantId, {
$set: {
subscriptionActive: true,
subscriptionDue: dueDate,
subscriptionStarted: start,
},
}).catch((e) => {
throw newError(
"Nie udało się aktywować okresu próbnego.",
500
);
});
} else {
throw newError("Okres próbny został już wykorzystany.", 500);
}
}
async function checkIfCategoryExists(restaurant, category) {
const categories = restaurant.categories;
if (categories.includes(category)) {
@@ -241,6 +265,7 @@ async function fetchRestaurant(id) {
const data = await Restaurant.findById(id).catch((e) => {
throw newError("Nie udało się pobrać restauracji.", 500);
});
console.log("fetched restaurant");
return data;
}
@@ -254,11 +279,8 @@ async function fetchMultipleRestaurants(idArray) {
}
async function fetchAllDishesForRestaurant(restaurant) {
let dishes = [];
for (const dish of restaurant.dishes) {
let res = await fetchDish(dish._id);
if (res !== null) dishes.push(res);
}
const idList = restaurant.dishes;
const dishes = await Dish.find({ '_id': { $in: idList } });
return dishes;
}
@@ -337,6 +359,14 @@ async function initializePayment(restaurantId, userData, type) {
return payment;
}
async function setRestaurantVisibility(restaurantId, visible) {
await Restaurant.findByIdAndUpdate(restaurantId, { $set: { hidden: !visible } }).catch(
(e) => {
throw newError("Nie udało się zmienić dania.", 500);
}
);
}
exports.changeUserPass = changeUserPass;
exports.removeDish = removeDish;
exports.removeRestaurant = removeRestaurant;
@@ -353,3 +383,5 @@ exports.fetchAllDishesForRestaurant = fetchAllDishesForRestaurant;
exports.fetchDish = fetchDish;
exports.fetchUser = fetchUser;
exports.initializePayment = initializePayment;
exports.setRestaurantVisibility = setRestaurantVisibility;
exports.startTrial = startTrial;

View File

@@ -18,7 +18,8 @@ async function renameBlob(blobURL) {
const key = blobURL.replace(containerURL, "");
s3.copyObject({
CopySource: "menuicdn/" + key,
Bucket: "menuicdn",
Bucket: "menuicdn",
ACL: 'public-read',
Key: removePrefix(key)
}, (err) => {
if (err) {