Skip to content

Commit e3807c9

Browse files
committed
refractor(api): fixed some bugs including uncommeting auth key check and change the system id
1 parent d6592a4 commit e3807c9

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/controllers/v4/internal/rewards.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ export const getRewards = async (req, res) => {
1515
const { type } = req.query;
1616

1717
// Authorization check
18-
// if (!key || key !== process.env.ACCESS_KEY) {
19-
// return res.status(401).json({ message: 'Unauthorized' });
20-
// }
18+
if (!key || key !== process.env.ACCESS_KEY) {
19+
return res.status(401).json({ message: 'Unauthorized' });
20+
}
2121

2222
// Fetch only the rewards field
23-
const system = await System.findById('system').select('rewards');
23+
const system = await System.findById('sudo').select('rewards');
2424

2525
if (!system || !Array.isArray(system.rewards)) {
2626
return res.status(404).json({ message: 'No rewards found' });
2727
}
2828

2929
// If an ID is provided, return that specific reward
3030
if (id) {
31-
const reward = system.rewards.find(r => r._id === id);
31+
const reward = system.rewards.find(r => r._id === id.toUpperCase());
3232
if (!reward) {
3333
return res.status(404).json({ message: 'Reward not found' });
3434
}
@@ -69,7 +69,7 @@ export const createReward = async (req, res) => {
6969
return res.status(400).json({ message: 'Missing required reward fields' });
7070
}
7171

72-
const system = await System.findById('system');
72+
const system = await System.findById('sudo');
7373
if (!system) {
7474
return res.status(404).json({ message: 'System not found' });
7575
}
@@ -125,7 +125,7 @@ export const redeemReward = async (req, res) => {
125125
}
126126

127127
// Find the system document (assuming you have only one system doc)
128-
const system = await System.findById('system').select('rewards');
128+
const system = await System.findById('sudo').select('rewards');
129129
if (!system) {
130130
return res.status(500).json({ message: 'System configuration not found for rewards' });
131131
}

0 commit comments

Comments
 (0)