From 3c7e88d38952819414f0facffe026a77a7e8b90a Mon Sep 17 00:00:00 2001 From: leca Date: Wed, 13 Nov 2024 19:38:46 +0300 Subject: [PATCH] deleting old image of an abstract product on its update --- src/controllers/abstractproduct.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/controllers/abstractproduct.js b/src/controllers/abstractproduct.js index 94401a9..015d6fb 100644 --- a/src/controllers/abstractproduct.js +++ b/src/controllers/abstractproduct.js @@ -50,6 +50,10 @@ class AbstractProductController { targetPath = path.join(path.resolve(path.dirname('')) + `/uploads/${image_filename}.png`); fs.copyFileSync(tempPath, targetPath); fs.rmSync(tempPath); + + let previousImageHash = (await AbstractProductService.getByLocalId(groupId, localId)).image_filename + let previousImagePath = path.join(path.resolve(path.dirname('')), `/uploads/${previousImageHash}.png`); + fs.unlinkSync(previousImagePath) } if (barcode) await AbstractProductService.updateBarcode(groupId, localId, barcode);