Skip to content

Commit

Permalink
fix: improve list tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Dec 13, 2021
1 parent eb9dd9e commit 90e85fb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/db/db-client-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type AuthKey = {
}

export type AuthKeyItem = definitions['auth_key'] & {
uploads: number
has_uploads: boolean
}

export type AuthKeyItemOutput = {
Expand Down
4 changes: 2 additions & 2 deletions packages/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ export class DBClient {
*/
async listKeys (userId) {
/** @type {{ error: PostgrestError, data: Array<import('./db-client-types').AuthKeyItem> }} */
const { data, error } = await this._client.rpc('user_keys_list', { query_user_id: userId })
const { data, error } = await this._client.rpc('user_auth_keys_list', { query_user_id: userId })

if (error) {
throw new DBError(error)
Expand All @@ -675,7 +675,7 @@ export class DBClient {
name: ki.name,
secret: ki.secret,
created: ki.created,
hasUploads: Boolean(ki.uploads)
hasUploads: ki.has_uploads
}))
}

Expand Down
8 changes: 4 additions & 4 deletions packages/db/postgres/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DROP FUNCTION IF EXISTS create_key;
DROP FUNCTION IF EXISTS create_upload;
DROP FUNCTION IF EXISTS upsert_pin;
DROP FUNCTION IF EXISTS user_used_storage;
DROP FUNCTION IF EXISTS user_keys_list;
DROP FUNCTION IF EXISTS user_auth_keys_list;
DROP FUNCTION IF EXISTS content_dag_size_total;
DROP FUNCTION IF EXISTS pin_dag_size_total;
DROP FUNCTION IF EXISTS find_deals_by_content_cids;
Expand Down Expand Up @@ -196,14 +196,14 @@ BEGIN
END
$$;

CREATE OR REPLACE FUNCTION user_keys_list(query_user_id BIGINT)
CREATE OR REPLACE FUNCTION user_auth_keys_list(query_user_id BIGINT)
RETURNS TABLE
(
"id" text,
"name" text,
"secret" text,
"created" timestamptz,
"uploads" bigint
"has_uploads" boolean
)
LANGUAGE sql
AS
Expand All @@ -212,7 +212,7 @@ SELECT (ak.id)::TEXT AS id,
ak.name AS name,
ak.secret AS secret,
ak.inserted_at AS created,
CASE WHEN EXISTS(SELECT 42 FROM upload u WHERE ak.id = u.auth_key_id AND u.deleted_at IS NULL) THEN 1::BIGINT ELSE 0::BIGINT END
WHEN EXISTS(SELECT 42 FROM upload u WHERE ak.id = u.auth_key_id)
FROM auth_key ak
WHERE ak.user_id = query_user_id AND ak.deleted_at IS NULL
$$;
Expand Down

0 comments on commit 90e85fb

Please sign in to comment.