import express from "express";
import itemSubGroupsService from "~/services/item/subGroups";

// eslint-disable-next-line new-cap
const router = express.Router();

router.get("/", async function (req, res, next) {
	try {
		res.json(await itemSubGroupsService.getList(req.query.page));
	} catch (err) {
		next(err);
	}
});

router.post("/", async function (req, res, next) {
	try {
		res.json(await itemSubGroupsService.create(req.body));
	} catch (err) {
		next(err);
	}
});

router.put("/:id", async function (req, res, next) {
	try {
		res.json(await itemSubGroupsService.update(req.params.id, req.body));
	} catch (err) {
		next(err);
	}
});

router.delete("/:id", async function (req, res, next) {
	try {
		res.json(await itemSubGroupsService.remove(req.params.id));
	} catch (err) {
		next(err);
	}
});

export default router;
