Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add apiKey.js script to add API keys to database and update usage count. #43

Merged
merged 2 commits into from
Aug 12, 2024

Conversation

Murkeee
Copy link
Contributor

@Murkeee Murkeee commented Aug 12, 2024

  • Add tools/apiKey.js
  • Modified database/index.js
  • Modified database/types.js

Description

This PR fixes #28

Notes for Reviewers
Hopefully this is what you want. One function for adding api key to database and another for updating the usage count. Let me know if changes need to be made.

Signed commits

  • Yes, I signed my commits.

- Add tools/apiKey.js
- Modified database/index.js
- Modified database/types.js

Signed-off-by: Tyson Dai <[email protected]>
tools/apiKey.js Outdated Show resolved Hide resolved
changed function name from test() to add keyToTable()

Signed-off-by: Tyson Dai <[email protected]>
@cbh778899 cbh778899 merged commit 42d2f51 into SkywardAI:main Aug 12, 2024
3 of 4 checks passed
@Murkeee
Copy link
Contributor Author

Murkeee commented Aug 12, 2024

In that case should functions return status codes like this?

if ( keyQuery.length == 0){
        await tbl.add([{api_key: key, usage: MAX_USAGE}]);
        return res.status(200).send(`Data with values: api_key: ${key}, usage: ${usage}, successfully added to table`)
    }
    else {
        return res.status(406).send("Attempted to add existing key to table");
    }

Or should that be handled differently?

@cbh778899
Copy link
Collaborator

In that case should functions return status codes like this?

if ( keyQuery.length == 0){
        await tbl.add([{api_key: key, usage: MAX_USAGE}]);
        return res.status(200).send(`Data with values: api_key: ${key}, usage: ${usage}, successfully added to table`)
    }
    else {
        return res.status(406).send("Attempted to add existing key to table");
    }

Or should that be handled differently?

no, i think this should be handled by functions in /actions/*.js files, they are specifically for req/res related actions.

@Murkeee
Copy link
Contributor Author

Murkeee commented Aug 12, 2024

👍 Got it. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Add token management
2 participants