Skip to content

Commit

Permalink
Add DELETE route to API keys
Browse files Browse the repository at this point in the history
  • Loading branch information
dangtony98 committed Jan 4, 2023
1 parent c7fb920 commit d3efe35
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
26 changes: 26 additions & 0 deletions backend/src/controllers/v2/apiKeyDataController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,30 @@ export const createAPIKeyData = async (req: Request, res: Response) => {
apiKey,
apiKeyData
});
}

/**
* Delete API key data with id [apiKeyDataId].
* @param req
* @param res
* @returns
*/
export const deleteAPIKeyData = async (req: Request, res: Response) => {
let apiKeyData;
try {
const { apiKeyDataId } = req.params;

apiKeyData = await APIKeyData.findByIdAndDelete(apiKeyDataId);

} catch (err) {
Sentry.setUser({ email: req.user.email });
Sentry.captureException(err);
return res.status(400).send({
message: 'Failed to delete API key data'
});
}

return res.status(200).send({
apiKeyData
});
}
12 changes: 11 additions & 1 deletion backend/src/routes/v2/apiKeyData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
requireAuth,
validateRequest
} from '../../middleware';
import { body } from 'express-validator';
import { param, body } from 'express-validator';
import { apiKeyDataController } from '../../controllers/v2';

router.get(
Expand All @@ -26,4 +26,14 @@ router.post(
apiKeyDataController.createAPIKeyData
);

router.delete(
'/:apiKeyDataId',
requireAuth({
acceptedAuthModes: ['jwt']
}),
param('apiKeyDataId').exists().trim(),
validateRequest,
apiKeyDataController.deleteAPIKeyData
);

export default router;

0 comments on commit d3efe35

Please sign in to comment.