add /users/me endpoint to user adapter
This commit is contained in:
parent
242aa7c0a9
commit
9ee90fc6fc
3 changed files with 41 additions and 4 deletions
|
|
@ -18,7 +18,10 @@ interface ApiUserResponse {
|
|||
role: number
|
||||
granblueId?: number | string | null // API returns number, transformed to camelCase
|
||||
showGamertag?: boolean // transformed from show_gamertag
|
||||
showGranblueId?: boolean // transformed from show_granblue_id
|
||||
collectionPrivacy?: number // transformed from collection_privacy (0=everyone, 1=crew_only, 2=private)
|
||||
gamertag?: string
|
||||
email?: string // Only included in settings view
|
||||
avatar: {
|
||||
picture: string
|
||||
element: string
|
||||
|
|
@ -39,6 +42,8 @@ export interface UserInfo {
|
|||
role: number
|
||||
granblueId?: string
|
||||
showCrewGamertag?: boolean
|
||||
showGranblueId?: boolean
|
||||
collectionPrivacy?: number
|
||||
crewGamertag?: string
|
||||
avatar: {
|
||||
picture: string
|
||||
|
|
@ -46,6 +51,13 @@ export interface UserInfo {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User settings info - includes email (only returned by /users/me endpoint)
|
||||
*/
|
||||
export interface UserSettings extends UserInfo {
|
||||
email: string
|
||||
}
|
||||
|
||||
export interface UserProfile extends UserInfo {
|
||||
parties?: Party[]
|
||||
}
|
||||
|
|
@ -76,12 +88,25 @@ function transformUserResponse(apiUser: ApiUserResponse): UserInfo {
|
|||
granblueId: apiUser.granblueId != null ? String(apiUser.granblueId) : undefined,
|
||||
// Rename showGamertag to showCrewGamertag
|
||||
showCrewGamertag: apiUser.showGamertag,
|
||||
// Privacy settings
|
||||
showGranblueId: apiUser.showGranblueId,
|
||||
collectionPrivacy: apiUser.collectionPrivacy,
|
||||
// Rename gamertag to crewGamertag
|
||||
crewGamertag: apiUser.gamertag,
|
||||
avatar: apiUser.avatar
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform API user response to frontend UserSettings format (includes email)
|
||||
*/
|
||||
function transformSettingsResponse(apiUser: ApiUserResponse): UserSettings {
|
||||
return {
|
||||
...transformUserResponse(apiUser),
|
||||
email: apiUser.email ?? ''
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapter for user-related API operations
|
||||
*/
|
||||
|
|
@ -230,11 +255,11 @@ export class UserAdapter extends BaseAdapter {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get current user
|
||||
* Get current user settings (includes email - only for settings modal)
|
||||
*/
|
||||
async getCurrentUser(): Promise<UserInfo> {
|
||||
async getCurrentUser(): Promise<UserSettings> {
|
||||
const result = await this.request<ApiUserResponse>('/users/me')
|
||||
return transformUserResponse(result)
|
||||
return transformSettingsResponse(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ export interface UserUpdateParams {
|
|||
theme?: string | undefined
|
||||
granblueId?: string | undefined
|
||||
showCrewGamertag?: boolean | undefined
|
||||
showGranblueId?: boolean | undefined
|
||||
collectionPrivacy?: number | undefined
|
||||
}
|
||||
|
||||
export interface UserResponse {
|
||||
|
|
@ -23,6 +25,8 @@ export interface UserResponse {
|
|||
role: number
|
||||
granblueId?: string
|
||||
showCrewGamertag?: boolean
|
||||
showGranblueId?: boolean
|
||||
collectionPrivacy?: number
|
||||
}
|
||||
|
||||
export const users = {
|
||||
|
|
@ -39,6 +43,8 @@ export const users = {
|
|||
theme?: string | undefined
|
||||
granblue_id?: string | undefined
|
||||
show_gamertag?: boolean | undefined
|
||||
show_granblue_id?: boolean | undefined
|
||||
collection_privacy?: number | undefined
|
||||
} = {}
|
||||
|
||||
if (params.picture !== undefined) updates.picture = params.picture
|
||||
|
|
@ -48,6 +54,8 @@ export const users = {
|
|||
if (params.theme !== undefined) updates.theme = params.theme
|
||||
if (params.granblueId !== undefined) updates.granblue_id = params.granblueId
|
||||
if (params.showCrewGamertag !== undefined) updates.show_gamertag = params.showCrewGamertag
|
||||
if (params.showGranblueId !== undefined) updates.show_granblue_id = params.showGranblueId
|
||||
if (params.collectionPrivacy !== undefined) updates.collection_privacy = params.collectionPrivacy
|
||||
|
||||
const result = await userAdapter.updateProfile(updates)
|
||||
return {
|
||||
|
|
@ -59,7 +67,9 @@ export const users = {
|
|||
theme: result.theme,
|
||||
role: result.role,
|
||||
granblueId: result.granblueId,
|
||||
showCrewGamertag: result.showCrewGamertag
|
||||
showCrewGamertag: result.showCrewGamertag,
|
||||
showGranblueId: result.showGranblueId,
|
||||
collectionPrivacy: result.collectionPrivacy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
src/lib/types/UserCookie.d.ts
vendored
2
src/lib/types/UserCookie.d.ts
vendored
|
|
@ -7,4 +7,6 @@ export interface UserCookie {
|
|||
bahamut?: boolean
|
||||
granblueId?: string
|
||||
showCrewGamertag?: boolean
|
||||
showGranblueId?: boolean
|
||||
collectionPrivacy?: number
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue