-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feature) Add option to list and add api keys from api
- Loading branch information
1 parent
0fe61ca
commit bc2d4db
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import ApiResponseHandler from "api-response-handler" | ||
import { Request, Response } from "express" | ||
import { AppDataSource } from "data-source" | ||
import { ApiKey } from "models" | ||
|
||
export const listKeys = async ( | ||
req: Request, | ||
res: Response, | ||
): Promise<void> => { | ||
const keys = await AppDataSource.getRepository(ApiKey).find() | ||
return ApiResponseHandler.success(res, keys.map((v) => "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx" + v.apiKey.slice(-4))) | ||
} | ||
|
||
export const createKey = async ( | ||
req: Request, | ||
res: Response, | ||
): Promise<void> => { | ||
const { name: keyName } = req.body | ||
const newKey = ApiKey.create({ name: keyName }) | ||
const key = await AppDataSource.getRepository(ApiKey).save( | ||
newKey, | ||
) | ||
return ApiResponseHandler.success(res, { | ||
apiKey: key.apiKey | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters