Skip to content

Commit

Permalink
public consumer added
Browse files Browse the repository at this point in the history
  • Loading branch information
shohan-pherones committed Jul 18, 2023
1 parent d6070d7 commit ca0d884
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions controllers/consumer.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,30 @@ const getPublicConsumers = async (req, res) => {
}
};

const getAPublicConsumer = async (req, res) => {
try {
const { cid } = req.params;

if (!mongoose.Types.ObjectId.isValid(cid)) {
throw new Error("Consumer not found.");
}

const consumer = await Consumer.findById(cid)
.populate("consumptions")
.populate("user")
.exec();

res.status(200).json(consumer);
} catch (error) {
res.status(400).json({ error: error.message });
}
};

module.exports = {
createConsumer,
getAllConsumers,
getAConsumer,
createConsumption,
getPublicConsumers,
getAPublicConsumer,
};
2 changes: 2 additions & 0 deletions routes/consumer.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ const {
getAConsumer,
createConsumption,
getPublicConsumers,
getAPublicConsumer,
} = require("../controllers/consumer.controller");

const router = express.Router();

router.get("/all", getPublicConsumers);
router.get("/all/:cid", getAPublicConsumer);
router.post("/", isAuthenticated, isConsumerConnector, createConsumer);
router.get("/", isAuthenticated, isConsumerConnector, getAllConsumers);
router.get("/:cid", isAuthenticated, isConsumerConnector, getAConsumer);
Expand Down

0 comments on commit ca0d884

Please sign in to comment.