added endpoints for retreiving info about items
This commit is contained in:
		@@ -59,6 +59,26 @@ class AbstractProductController {
 | 
			
		||||
 | 
			
		||||
        return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async getById(req, res) {
 | 
			
		||||
        let { localId, groupId } = req.params
 | 
			
		||||
 | 
			
		||||
        let result = await AbstractProductService.getByLocalId(groupId, localId)
 | 
			
		||||
 | 
			
		||||
        return res.status(200).send(result)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async getImage(req, res) {
 | 
			
		||||
        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`);
 | 
			
		||||
 | 
			
		||||
        let image = fs.readFileSync(imagePath)
 | 
			
		||||
 | 
			
		||||
        return res.status(200).send(image)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default new AbstractProductController();
 | 
			
		||||
 
 | 
			
		||||
@@ -20,6 +20,14 @@ class CategoryController {
 | 
			
		||||
 | 
			
		||||
        return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async getByLocalId(req, res) {
 | 
			
		||||
        const { groupId, localId } = req.params;
 | 
			
		||||
 | 
			
		||||
        let result = await CategoryService.getById(groupId, localId)
 | 
			
		||||
 | 
			
		||||
        return res.status(200).send(result)
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default new CategoryController();
 | 
			
		||||
@@ -27,6 +27,14 @@ class AbstractProductController {
 | 
			
		||||
 | 
			
		||||
        return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async getByLocalId(req, res) {
 | 
			
		||||
        let { groupId, localId } = req.params;
 | 
			
		||||
 | 
			
		||||
        let result = await ProductService.getByLocalId(groupId, localId)
 | 
			
		||||
 | 
			
		||||
        return res.status(200).send(result)
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default new AbstractProductController();
 | 
			
		||||
@@ -14,5 +14,7 @@ const AbstractProductRouter = new Router();
 | 
			
		||||
 | 
			
		||||
AbstractProductRouter.post('/create', upload.single("file"), tryHandler(auth.authenticate), tryHandler(auth.userIsInGroup), tryHandler(AbstractProductController.create));
 | 
			
		||||
AbstractProductRouter.post('/update', upload.single("file"), tryHandler(auth.authenticate), tryHandler(auth.userIsInGroup), tryHandler(existance.localIdExists), tryHandler(AbstractProductController.update));
 | 
			
		||||
AbstractProductRouter.get('/:groupId/:localId', tryHandler(auth.authenticate), tryHandler(auth.userIsInGroup), tryHandler(existance.localIdExists), tryHandler(AbstractProductController.getById));
 | 
			
		||||
AbstractProductRouter.get('/getimage/:groupId/:localId', tryHandler(auth.authenticate), tryHandler(auth.userIsInGroup), tryHandler(existance.localIdExists), tryHandler(AbstractProductController.getImage));
 | 
			
		||||
 | 
			
		||||
export default AbstractProductRouter;
 | 
			
		||||
@@ -6,7 +6,8 @@ import existance from '../middlewares/existance.js';
 | 
			
		||||
 | 
			
		||||
const CategoryRouter = new Router();
 | 
			
		||||
 | 
			
		||||
CategoryRouter.post('/create', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(CategoryController.create));
 | 
			
		||||
CategoryRouter.post('/update', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(existance.localIdExists), tryHandler(CategoryController.update));
 | 
			
		||||
CategoryRouter.post('/create', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.userIsInGroup), tryHandler(CategoryController.create));
 | 
			
		||||
CategoryRouter.post('/update', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.userIsInGroup), tryHandler(existance.localIdExists), tryHandler(CategoryController.update));
 | 
			
		||||
CategoryRouter.get('/:groupId/:localId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.userIsInGroup), tryHandler(existance.localIdExists), tryHandler(CategoryController.getByLocalId))
 | 
			
		||||
 | 
			
		||||
export default CategoryRouter;
 | 
			
		||||
@@ -8,5 +8,6 @@ const ProductRouter = new Router();
 | 
			
		||||
 | 
			
		||||
ProductRouter.post('/create', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.userIsInGroup), tryHandler(ProductController.create));
 | 
			
		||||
ProductRouter.post('/update', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(existance.localIdExists), tryHandler(auth.userIsInGroup), tryHandler(ProductController.update));
 | 
			
		||||
ProductRouter.get('/:groupId/:localId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(existance.localIdExists), tryHandler(auth.userIsInGroup), tryHandler(ProductController.getByLocalId))
 | 
			
		||||
 | 
			
		||||
export default ProductRouter;
 | 
			
		||||
@@ -64,6 +64,12 @@ class AbstractProductService {
 | 
			
		||||
        if (!result) return false;
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async getByLocalId(groupId, localId) {
 | 
			
		||||
        let result = (await db.query("SELECT * FROM abstract_products WHERE group_id = $1 AND local_id = $2", [groupId, localId]))
 | 
			
		||||
        if (result.rowCount == 0) throw new customError(`Abstract product not found`, responses.responses.abstractproducts.not_found)
 | 
			
		||||
        return result.rows[0]
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default new AbstractProductService();
 | 
			
		||||
@@ -51,6 +51,12 @@ class ProductService {
 | 
			
		||||
        if (!result) return false;
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async getByLocalId(groupId, localId) {
 | 
			
		||||
        let result = (await db.query("SELECT * FROM products WHERE group_id = $1 AND local_id = $2", [groupId, localId]));
 | 
			
		||||
        if (result.rowCount == 0) throw new customError(`getByLocalId product not found`, responseCodes.responses.products.not_found);
 | 
			
		||||
        return responseCodes.rows[0];
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default new ProductService();
 | 
			
		||||
		Reference in New Issue
	
	Block a user