Skip to content

Commit

Permalink
feat: get rp by id
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafahincal committed Aug 31, 2024
1 parent c7c1efd commit 224d0f7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
12 changes: 12 additions & 0 deletions v1/src/controllers/rps.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
exportBySiteBoundToExcel: exportBySiteBound,
getExcelTemplate: getRPsExcelTemplate,
importFromXlsx: importRPsFromXlsx,
getRpById,
} = require('../services/rp.service');
const {
calculateDistributionCurves,
Expand Down Expand Up @@ -126,6 +127,16 @@ const getBySiteBoundId = async (req, res) => {
});
};

const getById = async (req, res) => {
const { rpId } = req.params;
const rp = await getRpById(rpId);
res.send({
rp,
success: true,
message: 'Rp listed successfully',
});
};

const distributionCurves = async (req, res) => {
const { rpIdList, sourceList, chartList } = req.body;
const result = [];
Expand Down Expand Up @@ -186,4 +197,5 @@ module.exports = {
getExcelTemplate,
importFromXlsx,
copyPaste,
getById,
};
4 changes: 2 additions & 2 deletions v1/src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const authenticateToken = require('../middlewares/authenticate');
router.use('/auth', require('./auth.routes'));
router.use('/users', require('./users.routes'));
router.use('/siteBounds', authenticateToken, require('./siteBounds.routes'));
router.use('/fields', authenticateToken, require('./sites.routes'));
router.use('/fields', require('./sites.routes'));
router.use('/projects', authenticateToken, require('./projects.routes'));
router.use('/rps', authenticateToken, require('./rps.routes'));
router.use('/rps', require('./rps.routes'));
router.use('/gprs', authenticateToken, require('./gprs.routes'));
router.use(
'/magnetometrics',
Expand Down
2 changes: 2 additions & 0 deletions v1/src/routes/rps.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
exportBySiteBoundToExcel,
getExcelTemplate,
importFromXlsx,
getById,
copyPaste,
} = require('../controllers/rps.controller');
const errorCatcher = require('../scripts/utils/errorCatcher');
Expand All @@ -20,6 +21,7 @@ const router = express.Router();

router.route('/').get(errorCatcher(index));
router.route('/:rpId').put(errorCatcher(update));
router.route('/:rpId').get(errorCatcher(getById));
router.route(`/copy-paste/:siteBoundId`).post(errorCatcher(copyPaste));
router.route('/:siteBoundId').get(errorCatcher(getBySiteBoundId));
router.route('/').post(errorCatcher(create));
Expand Down
11 changes: 11 additions & 0 deletions v1/src/services/rp.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ const getRpsBySiteBoundId = async (siteBoundId) => {
return rps;
};

const getRpById = async (id) => {
const rp = await Rp.findById(id);

if (!rp) {
throw new Error('rp not found');
}

return rp;
};

const getLastRpBySiteBoundId = async (siteBoundId) => {
const rp = await Rp.findOne({
siteBound: siteBoundId,
Expand Down Expand Up @@ -178,4 +188,5 @@ module.exports = {
exportBySiteBoundToExcel,
getExcelTemplate,
importFromXlsx,
getRpById,
};

0 comments on commit 224d0f7

Please sign in to comment.