-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
user spotify visibility setting now respected in friend and suer endp…
…oint.
- Loading branch information
Showing
6 changed files
with
82 additions
and
11 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 |
---|---|---|
@@ -1,15 +1,19 @@ | ||
CREATE TABLE users | ||
( | ||
id uuid not null references auth.users on delete cascade, | ||
avatar_url text, | ||
username text not null, | ||
spotify_id text not null, | ||
spotify_visibility boolean not null default false, | ||
id uuid not null references auth.users on delete cascade, | ||
avatar_url text, | ||
username text not null, | ||
spotify_id text not null, | ||
spotify_visibility boolean not null default false, | ||
created_at timestamp with time zone default now(), | ||
daily_streak integer not null default 0, | ||
daily_streak_updated_at timestamp with time zone not null default now(), | ||
primary key (id) | ||
); | ||
|
||
ALTER TABLE users | ||
ADD CONSTRAINT unique_username UNIQUE (username), | ||
ADD CONSTRAINT valid_username check (username <> '' AND length(trim(username)) >= 4 AND username ~ '^[a-zA-Z0-9_]+$'); | ||
ADD CONSTRAINT valid_username check (username <> '' AND length(trim(username)) >= 4 AND | ||
username ~ '^[a-zA-Z0-9_]+$'); | ||
|
||
CREATE INDEX idx_username ON users(username); | ||
CREATE INDEX idx_username ON users (username); |
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,5 +1,41 @@ | ||
export default defineEventHandler((event) => { | ||
import {isValidUUID} from "~/server/utils/data-validation"; | ||
import {serverSupabaseServiceRole, serverSupabaseUser} from "#supabase/server"; | ||
import type {GetUserResponse} from "~/types/api/users"; | ||
|
||
export default defineEventHandler(async (event) => { | ||
const userId = getRouterParam(event, 'uid') | ||
|
||
return; | ||
// Require user to be authenticated | ||
const user = await serverSupabaseUser(event); | ||
if (!user?.id) { | ||
setResponseStatus(event, 401); | ||
return {error: 'unauthenticated'}; | ||
} | ||
|
||
if (!userId || !isValidUUID(userId)) { | ||
setResponseStatus(event, 400); | ||
return {error: 'Invalid user ID'}; | ||
} | ||
|
||
// Send request | ||
const client = serverSupabaseServiceRole(event); | ||
const {data, error}:{ data: GetUserResponse|null, error: any} = await client.from('users').select('*').eq('id', userId).maybeSingle(); | ||
Check failure on line 22 in server/api/v1/user/[uid].get.ts GitHub Actions / eslint
|
||
|
||
if (!data) { | ||
setResponseStatus(event, 404); | ||
return {error: 'User not found'}; | ||
} | ||
|
||
// Handle errors | ||
if (error) { | ||
setResponseStatus(event, 500); | ||
return {error: error.message}; | ||
} | ||
|
||
// Hide spotify id if not visible | ||
if (!data.spotify_visibility) { | ||
delete data.spotify_id; | ||
} | ||
|
||
return data; | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type url from "node:url"; | ||
|
||
export interface GetUserResponse { | ||
id: string, | ||
avatar_url?: url.URL | null, | ||
username: string, | ||
spotify_id?: string, | ||
spotify_visibility: boolean, | ||
daily_streak: number, | ||
daily_streak_updated_at: string | ||
} |