Skip to content

Commit 9220c5a

Browse files
Merge pull request #2088 from OneCommunityGlobal/Sayali_PR_Grading_Create_Test_Config
Sayali: add PR grading config model, controller, and routes for dynamic test configuration
2 parents a318f6a + 2104c7b commit 9220c5a

4 files changed

Lines changed: 106 additions & 1 deletion

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const prGradingConfigController = function (PRGradingConfig) {
2+
const getAllConfigs = async (req, res) => {
3+
try {
4+
const configs = await PRGradingConfig.find().sort({ createdAt: -1 });
5+
res.status(200).json(configs);
6+
} catch (err) {
7+
res.status(500).json({ error: 'Failed to fetch configurations', details: err.message });
8+
}
9+
};
10+
11+
const createConfig = async (req, res) => {
12+
try {
13+
const { teamName, reviewerCount, testDataType, reviewerNames, notes } = req.body;
14+
15+
if (!teamName || !reviewerCount || !testDataType) {
16+
return res
17+
.status(400)
18+
.json({ error: 'teamName, reviewerCount, and testDataType are required.' });
19+
}
20+
21+
if (typeof reviewerCount !== 'number' || reviewerCount < 1) {
22+
return res.status(400).json({ error: 'reviewerCount must be a positive number.' });
23+
}
24+
25+
const existing = await PRGradingConfig.findOne({ teamName: teamName.trim() });
26+
if (existing) {
27+
return res
28+
.status(409)
29+
.json({ error: `A configuration with team name "${teamName}" already exists.` });
30+
}
31+
32+
const newConfig = new PRGradingConfig({
33+
teamName: teamName.trim(),
34+
reviewerCount,
35+
testDataType,
36+
reviewerNames: reviewerNames || [],
37+
notes: notes || '',
38+
});
39+
40+
const saved = await newConfig.save();
41+
res.status(201).json(saved);
42+
} catch (err) {
43+
res.status(500).json({ error: 'Failed to create configuration', details: err.message });
44+
}
45+
};
46+
47+
const deleteConfig = async (req, res) => {
48+
try {
49+
const { id } = req.params;
50+
const deleted = await PRGradingConfig.findByIdAndDelete(id);
51+
if (!deleted) {
52+
return res.status(404).json({ error: 'Configuration not found.' });
53+
}
54+
res.status(200).json({ message: 'Configuration deleted successfully.' });
55+
} catch (err) {
56+
res.status(500).json({ error: 'Failed to delete configuration', details: err.message });
57+
}
58+
};
59+
60+
return { getAllConfigs, createConfig, deleteConfig };
61+
};
62+
63+
module.exports = prGradingConfigController;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const mongoose = require('mongoose');
2+
3+
const { Schema } = mongoose;
4+
5+
const PRGradingConfigSchema = new Schema(
6+
{
7+
teamName: { type: String, required: true, unique: true, trim: true },
8+
reviewerCount: { type: Number, required: true, min: 1 },
9+
testDataType: {
10+
type: String,
11+
enum: ['minimal', 'mixed', 'edge cases', 'custom'],
12+
required: true,
13+
},
14+
reviewerNames: [{ type: String, trim: true }],
15+
notes: { type: String, trim: true, default: '' },
16+
},
17+
{
18+
timestamps: true,
19+
},
20+
);
21+
22+
module.exports = mongoose.model('PRGradingConfig', PRGradingConfigSchema, 'prGradingConfigs');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const express = require('express');
2+
3+
const routes = function (PRGradingConfig) {
4+
const prGradingConfigRouter = express.Router();
5+
const controller = require('../../controllers/prAnalytics/prGradingConfigController')(
6+
PRGradingConfig,
7+
);
8+
9+
prGradingConfigRouter.route('/pr-grading-config').get(controller.getAllConfigs);
10+
prGradingConfigRouter.route('/pr-grading-config').post(controller.createConfig);
11+
prGradingConfigRouter.route('/pr-grading-config/:id').delete(controller.deleteConfig);
12+
13+
return prGradingConfigRouter;
14+
};
15+
16+
module.exports = routes;

src/startup/routes.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ const popularityEnhancedRoutes = require('../routes/popularityEnhancedRoutes');
4343

4444
const PRReviewInsights = require('../models/prAnalytics/prReviewsInsights');
4545
const WeeklyGrading = require('../models/prAnalytics/weeklyGrading');
46+
const PRGradingConfig = require('../models/prAnalytics/prGradingConfig');
47+
const prGradingConfigRouter = require('../routes/prAnalytics/prGradingConfigRouter')(
48+
PRGradingConfig,
49+
);
4650

4751
// Title
4852
const title = require('../models/title');
@@ -498,7 +502,6 @@ module.exports = function (app) {
498502
app.use('/api', toolUtilizationRouter);
499503
// lb dashboard
500504

501-
502505
app.use('/api', toolAvailabilityRouter);
503506
app.use('/api', projectCostTrackingRouter);
504507

@@ -555,6 +558,7 @@ module.exports = function (app) {
555558
// PR Analytics
556559
app.use('/api', prInsightsRouter);
557560
app.use('/api', weeklyGradingRouter);
561+
app.use('/api', prGradingConfigRouter);
558562
app.use('/api', projectMaterialRouter);
559563
app.use('/api/bm', bmRentalChart);
560564
app.use('/api/lb', lbWishlistsRouter);

0 commit comments

Comments
 (0)