Add DELETE route to API keys

This commit is contained in:
Tuan Dang
2023-01-04 20:38:37 +07:00
parent c7fb9209c4
commit d3efe351f1
2 changed files with 37 additions and 1 deletions
@@ -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
});
}