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
|
role: number
|
||||||
granblueId?: number | string | null // API returns number, transformed to camelCase
|
granblueId?: number | string | null // API returns number, transformed to camelCase
|
||||||
showGamertag?: boolean // transformed from show_gamertag
|
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
|
gamertag?: string
|
||||||
|
email?: string // Only included in settings view
|
||||||
avatar: {
|
avatar: {
|
||||||
picture: string
|
picture: string
|
||||||
element: string
|
element: string
|
||||||
|
|
@ -39,6 +42,8 @@ export interface UserInfo {
|
||||||
role: number
|
role: number
|
||||||
granblueId?: string
|
granblueId?: string
|
||||||
showCrewGamertag?: boolean
|
showCrewGamertag?: boolean
|
||||||
|
showGranblueId?: boolean
|
||||||
|
collectionPrivacy?: number
|
||||||
crewGamertag?: string
|
crewGamertag?: string
|
||||||
avatar: {
|
avatar: {
|
||||||
picture: string
|
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 {
|
export interface UserProfile extends UserInfo {
|
||||||
parties?: Party[]
|
parties?: Party[]
|
||||||
}
|
}
|
||||||
|
|
@ -76,12 +88,25 @@ function transformUserResponse(apiUser: ApiUserResponse): UserInfo {
|
||||||
granblueId: apiUser.granblueId != null ? String(apiUser.granblueId) : undefined,
|
granblueId: apiUser.granblueId != null ? String(apiUser.granblueId) : undefined,
|
||||||
// Rename showGamertag to showCrewGamertag
|
// Rename showGamertag to showCrewGamertag
|
||||||
showCrewGamertag: apiUser.showGamertag,
|
showCrewGamertag: apiUser.showGamertag,
|
||||||
|
// Privacy settings
|
||||||
|
showGranblueId: apiUser.showGranblueId,
|
||||||
|
collectionPrivacy: apiUser.collectionPrivacy,
|
||||||
// Rename gamertag to crewGamertag
|
// Rename gamertag to crewGamertag
|
||||||
crewGamertag: apiUser.gamertag,
|
crewGamertag: apiUser.gamertag,
|
||||||
avatar: apiUser.avatar
|
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
|
* 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')
|
const result = await this.request<ApiUserResponse>('/users/me')
|
||||||
return transformUserResponse(result)
|
return transformSettingsResponse(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ export interface UserUpdateParams {
|
||||||
theme?: string | undefined
|
theme?: string | undefined
|
||||||
granblueId?: string | undefined
|
granblueId?: string | undefined
|
||||||
showCrewGamertag?: boolean | undefined
|
showCrewGamertag?: boolean | undefined
|
||||||
|
showGranblueId?: boolean | undefined
|
||||||
|
collectionPrivacy?: number | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserResponse {
|
export interface UserResponse {
|
||||||
|
|
@ -23,6 +25,8 @@ export interface UserResponse {
|
||||||
role: number
|
role: number
|
||||||
granblueId?: string
|
granblueId?: string
|
||||||
showCrewGamertag?: boolean
|
showCrewGamertag?: boolean
|
||||||
|
showGranblueId?: boolean
|
||||||
|
collectionPrivacy?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export const users = {
|
export const users = {
|
||||||
|
|
@ -39,6 +43,8 @@ export const users = {
|
||||||
theme?: string | undefined
|
theme?: string | undefined
|
||||||
granblue_id?: string | undefined
|
granblue_id?: string | undefined
|
||||||
show_gamertag?: boolean | undefined
|
show_gamertag?: boolean | undefined
|
||||||
|
show_granblue_id?: boolean | undefined
|
||||||
|
collection_privacy?: number | undefined
|
||||||
} = {}
|
} = {}
|
||||||
|
|
||||||
if (params.picture !== undefined) updates.picture = params.picture
|
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.theme !== undefined) updates.theme = params.theme
|
||||||
if (params.granblueId !== undefined) updates.granblue_id = params.granblueId
|
if (params.granblueId !== undefined) updates.granblue_id = params.granblueId
|
||||||
if (params.showCrewGamertag !== undefined) updates.show_gamertag = params.showCrewGamertag
|
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)
|
const result = await userAdapter.updateProfile(updates)
|
||||||
return {
|
return {
|
||||||
|
|
@ -59,7 +67,9 @@ export const users = {
|
||||||
theme: result.theme,
|
theme: result.theme,
|
||||||
role: result.role,
|
role: result.role,
|
||||||
granblueId: result.granblueId,
|
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
|
bahamut?: boolean
|
||||||
granblueId?: string
|
granblueId?: string
|
||||||
showCrewGamertag?: boolean
|
showCrewGamertag?: boolean
|
||||||
|
showGranblueId?: boolean
|
||||||
|
collectionPrivacy?: number
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue