deleting old image of an abstract product on its update

This commit is contained in:
leca 2024-11-13 19:38:46 +03:00
parent eb0c8ac99d
commit 3c7e88d389
1 changed files with 4 additions and 0 deletions

View File

@ -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);