|
|
@ -50,6 +50,10 @@ class AbstractProductController {
|
|
|
|
targetPath = path.join(path.resolve(path.dirname('')) + `/uploads/${image_filename}.png`);
|
|
|
|
targetPath = path.join(path.resolve(path.dirname('')) + `/uploads/${image_filename}.png`);
|
|
|
|
fs.copyFileSync(tempPath, targetPath);
|
|
|
|
fs.copyFileSync(tempPath, targetPath);
|
|
|
|
fs.rmSync(tempPath);
|
|
|
|
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);
|
|
|
|
if (barcode) await AbstractProductService.updateBarcode(groupId, localId, barcode);
|
|
|
@ -93,6 +97,10 @@ class AbstractProductController {
|
|
|
|
async delete(req, res) {
|
|
|
|
async delete(req, res) {
|
|
|
|
let { localId, groupId } = req.params;
|
|
|
|
let { localId, groupId } = req.params;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let imageFilename = (await AbstractProductService.getByLocalId(groupId, localId)).image_filename
|
|
|
|
|
|
|
|
let imagePath = path.join(path.resolve(path.dirname('')), `/uploads/${imageFilename}.png`);
|
|
|
|
|
|
|
|
fs.unlinkSync(imagePath)
|
|
|
|
|
|
|
|
|
|
|
|
await AbstractProductService.delete(groupId, localId)
|
|
|
|
await AbstractProductService.delete(groupId, localId)
|
|
|
|
|
|
|
|
|
|
|
|
notify(req.headers.authorization.split(' ')[1], groupId, 'delete', 'abstractproduct', { local_id: localId });
|
|
|
|
notify(req.headers.authorization.split(' ')[1], groupId, 'delete', 'abstractproduct', { local_id: localId });
|
|
|
|