Skip to content

Commit

Permalink
chore: use Firebase Id to fetch developer
Browse files Browse the repository at this point in the history
  • Loading branch information
ijemmao committed Mar 24, 2024
1 parent 1f29c6c commit dfd3dd9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
9 changes: 3 additions & 6 deletions src/controllers/developers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,14 @@ export const putDeveloper: MiddleWare = async (req, res, next) => {
}
};

/** Gets a Developer by the MongoDB Id, Firebase Id, Email */
/** Gets a Developer by the Firebase Id */
export const getDeveloper: MiddleWare = async (req, res, next) => {
const connection = createDbConnection();
const Developer = connection.model<DeveloperType>('Developer', developerSchema);
const { firebaseId, email } = req.body;
const { id } = req.params;
const { id: firebaseId } = req.params;

try {
const developer = await Developer.findOne({
$or: [{ firebaseId }, { email }, { _id: new Types.ObjectId(id) }],
});
const developer = await Developer.findOne({ firebaseId });
if (!developer) {
throw new Error('No associated developer found.');
}
Expand Down
3 changes: 0 additions & 3 deletions src/pages/APIs/DevelopersAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ export const getDeveloper = async (firebaseId: string): Promise<Developer> => {
const res = await axios<Developer>({
method: 'GET',
url: `/api/v1/developers/${firebaseId}`,
data: {
firebaseId,
},
});
return res.data;
};
2 changes: 1 addition & 1 deletion src/routers/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ router.get('/words/:id', validateApiKey, validId, attachRedisClient, getWord);
router.get('/examples', validateApiKey, attachRedisClient, getExamples);
router.get('/examples/:id', validateApiKey, validId, attachRedisClient, getExample);

router.get('/developers/:id', postDeveloper, validateUpdateDeveloperBody, getDeveloper);
router.get('/developers/:id', developerRateLimiter, getDeveloper);
router.post('/developers', developerRateLimiter, validateDeveloperBody, postDeveloper);
router.put('/developers', developerRateLimiter, validateUpdateDeveloperBody, putDeveloper);

Expand Down

0 comments on commit dfd3dd9

Please sign in to comment.