server v1.0.5
//delete image //delete restaurant //update restaurant
This commit is contained in:
@@ -75,3 +75,12 @@ export function setDeleteTempBlobTimer(blobName, containerClient, minutes) {
|
||||
blob.delete();
|
||||
}, 1000 * 60 * minutes);
|
||||
}
|
||||
|
||||
export async function deleteImage(url) {
|
||||
const containerClient = blobServiceClient.getContainerClient(container);
|
||||
const containerUrl = containerClient.url + "/";
|
||||
const blobName = url.replace(containerUrl, "");
|
||||
console.log(`BLOB NAME = ${blobName}`);
|
||||
const blob = containerClient.getBlobClient(blobName);
|
||||
await blob.delete();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import Dish from "../models/dish.js";
|
||||
import User from "../models/users.js";
|
||||
import Restaurant from "../models/restaurant.js";
|
||||
import { fetchMultipleRestaurants } from "./databaseServices.js";
|
||||
import { deleteImage } from "./azureServices.js";
|
||||
|
||||
export async function createUser(request) {
|
||||
const password = await hashPass(request.body.password);
|
||||
@@ -25,20 +26,21 @@ export async function createUser(request) {
|
||||
|
||||
async function handleImageUpdate(request, previous) {
|
||||
if (!previous) {
|
||||
if (!request.imgURL) {
|
||||
if (!request.imgUrl) {
|
||||
return "empty";
|
||||
} else {
|
||||
const img = await saveImage(request.imgURL);
|
||||
const img = await saveImage(request.imgUrl);
|
||||
return img;
|
||||
}
|
||||
} else {
|
||||
if (request.imgURL == previous.imgUrl) {
|
||||
if (request.imgUrl == previous.imgUrl) {
|
||||
return previous.imgUrl;
|
||||
} else {
|
||||
if (!request.imgURL) {
|
||||
if (!request.imgUrl) {
|
||||
return previous.imgUrl;
|
||||
} else {
|
||||
const img = await saveImage(request.imgURL);
|
||||
const img = await saveImage(request.imgUrl);
|
||||
await deleteImage(previous.imgUrl);
|
||||
return img;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Restaurant from "../models/restaurant.js";
|
||||
import Dish from "../models/dish.js";
|
||||
import User from "../models/users.js";
|
||||
import { deleteImage } from "./azureServices.js";
|
||||
import { newError } from "./services.js";
|
||||
|
||||
export async function changeUserPass(userId, newPass) {
|
||||
@@ -26,6 +27,13 @@ export async function removeRestaurant(restaurantId, userId) {
|
||||
throw newError("Usunięcie nie powiodło się.", 500);
|
||||
}
|
||||
);
|
||||
await deleteImage(deletedDoc.imgUrl);
|
||||
for (dishId of deletedDoc.dishes) {
|
||||
const deletedDish = await Dish.findByIdAndDelete(dishId).catch((e) =>
|
||||
console.log(e)
|
||||
);
|
||||
await deleteImage(deletedDish.imgUrl);
|
||||
}
|
||||
await User.findByIdAndUpdate(userId, {
|
||||
$pull: { restaurants: restaurantId },
|
||||
}).catch((e) => {
|
||||
|
||||
Reference in New Issue
Block a user