-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from DestinyItemManager/upgrade-types
Upgrade stuff + get rid of any + lints
- Loading branch information
Showing
47 changed files
with
2,808 additions
and
1,673 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
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
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 |
---|---|---|
|
@@ -13,7 +13,6 @@ ca.key | |
.brackets.json | ||
.npmrc | ||
npm-debug.log | ||
.nvmrc | ||
yarn-error.log | ||
coverage/ | ||
dim-api-types/*.js | ||
|
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 @@ | ||
20 |
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
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 |
---|---|---|
@@ -1,54 +1,42 @@ | ||
import { ClientBase, QueryResult } from 'pg'; | ||
import { ApiApp } from '../shapes/app.js'; | ||
import { camelize } from '../utils.js'; | ||
import { camelize, KeysToSnakeCase, TypesForKeys } from '../utils.js'; | ||
|
||
/** | ||
* Get all registered apps. | ||
*/ | ||
export async function getAllApps(client: ClientBase): Promise<ApiApp[]> { | ||
try { | ||
const results = await client.query<ApiApp>({ | ||
name: 'get_all_apps', | ||
text: 'SELECT * FROM apps', | ||
}); | ||
return results.rows.map((row) => camelize<ApiApp>(row)); | ||
} catch (e) { | ||
throw new Error(e.name + ': ' + e.message); | ||
} | ||
const results = await client.query<KeysToSnakeCase<ApiApp>>({ | ||
name: 'get_all_apps', | ||
text: 'SELECT * FROM apps', | ||
}); | ||
return results.rows.map((row) => camelize(row)); | ||
} | ||
|
||
/** | ||
* Get an app by its ID. | ||
*/ | ||
export async function getAppById(client: ClientBase, id: string): Promise<ApiApp | null> { | ||
try { | ||
const results = await client.query<ApiApp>({ | ||
name: 'get_apps', | ||
text: 'SELECT * FROM apps where id = $1', | ||
values: [id], | ||
}); | ||
if (results.rows.length > 0) { | ||
return camelize<ApiApp>(results.rows[0]); | ||
} else { | ||
return null; | ||
} | ||
} catch (e) { | ||
throw new Error(e.name + ': ' + e.message); | ||
const results = await client.query<KeysToSnakeCase<ApiApp>>({ | ||
name: 'get_apps', | ||
text: 'SELECT * FROM apps where id = $1', | ||
values: [id], | ||
}); | ||
if (results.rows.length > 0) { | ||
return camelize(results.rows[0]); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Insert a new app into the list of registered apps. | ||
*/ | ||
export async function insertApp(client: ClientBase, app: ApiApp): Promise<QueryResult<any>> { | ||
try { | ||
return client.query({ | ||
name: 'insert_app', | ||
text: `insert into apps (id, bungie_api_key, dim_api_key, origin) | ||
export async function insertApp(client: ClientBase, app: ApiApp): Promise<QueryResult> { | ||
return client.query<any, TypesForKeys<ApiApp, ['id', 'bungieApiKey', 'dimApiKey', 'origin']>>({ | ||
name: 'insert_app', | ||
text: `insert into apps (id, bungie_api_key, dim_api_key, origin) | ||
values ($1, $2, $3, $4)`, | ||
values: [app.id, app.bungieApiKey, app.dimApiKey, app.origin], | ||
}); | ||
} catch (e) { | ||
throw new Error(e.name + ': ' + e.message); | ||
} | ||
values: [app.id, app.bungieApiKey, app.dimApiKey, app.origin], | ||
}); | ||
} |
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
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
Oops, something went wrong.