fix: API adapters and type mapping
- transform job skills pagination meta to include page/perPage - fix UserInfo avatar type (optional properties -> required when present) - add visibility number-to-string mapping in party service (0=public, 1=private, 2=unlisted) - change mapToApiPayload return type from Partial<Party> to CreatePartyParams - fix raid/job mapping to use IDs instead of nested objects - add generic type argument to RestDataProvider<any> - add type assertion in optionalProps (value as T[keyof T])
This commit is contained in:
parent
073bed01d3
commit
009758a997
5 changed files with 26 additions and 13 deletions
|
|
@ -131,7 +131,12 @@ export class JobAdapter extends BaseAdapter {
|
||||||
page: params.page || 1,
|
page: params.page || 1,
|
||||||
total: response.meta?.count || 0,
|
total: response.meta?.count || 0,
|
||||||
totalPages: response.meta?.total_pages || 1,
|
totalPages: response.meta?.total_pages || 1,
|
||||||
meta: response.meta
|
meta: response.meta ? {
|
||||||
|
count: response.meta.count ?? 0,
|
||||||
|
page: params.page || 1,
|
||||||
|
perPage: response.meta.per_page ?? 10,
|
||||||
|
totalPages: response.meta.total_pages ?? 1
|
||||||
|
} : undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ export const users = {
|
||||||
gender?: number | undefined
|
gender?: number | undefined
|
||||||
language?: string | undefined
|
language?: string | undefined
|
||||||
theme?: string | undefined
|
theme?: string | undefined
|
||||||
avatar?: { picture?: string | undefined; element?: string | undefined } | undefined
|
avatar?: { picture: string; element: string } | undefined
|
||||||
} = {}
|
} = {}
|
||||||
|
|
||||||
if (params.gender !== undefined) updates.gender = params.gender
|
if (params.gender !== undefined) updates.gender = params.gender
|
||||||
|
|
@ -39,10 +39,10 @@ export const users = {
|
||||||
if (params.theme !== undefined) updates.theme = params.theme
|
if (params.theme !== undefined) updates.theme = params.theme
|
||||||
|
|
||||||
if (params.picture !== undefined || params.element !== undefined) {
|
if (params.picture !== undefined || params.element !== undefined) {
|
||||||
const avatar: { picture?: string | undefined; element?: string | undefined } = {}
|
updates.avatar = {
|
||||||
if (params.picture !== undefined) avatar.picture = params.picture
|
picture: params.picture ?? '',
|
||||||
if (params.element !== undefined) avatar.element = params.element
|
element: params.element ?? ''
|
||||||
updates.avatar = avatar
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await userAdapter.updateProfile(updates)
|
const result = await userAdapter.updateProfile(updates)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ interface APIResponse {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DatabaseProvider extends RestDataProvider {
|
export class DatabaseProvider extends RestDataProvider<any> {
|
||||||
private resource: 'weapons' | 'characters' | 'summons'
|
private resource: 'weapons' | 'characters' | 'summons'
|
||||||
private pageSize: number
|
private pageSize: number
|
||||||
private currentPage: number = 1
|
private currentPage: number = 1
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import type { Party } from '$lib/types/api/party'
|
import type { Party } from '$lib/types/api/party'
|
||||||
import { partyAdapter } from '$lib/api/adapters/party.adapter'
|
import { partyAdapter, type CreatePartyParams } from '$lib/api/adapters/party.adapter'
|
||||||
import { authStore } from '$lib/stores/auth.store'
|
import { authStore } from '$lib/stores/auth.store'
|
||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
|
|
||||||
|
|
@ -279,13 +279,13 @@ export class PartyService {
|
||||||
return headers
|
return headers
|
||||||
}
|
}
|
||||||
|
|
||||||
private mapToApiPayload(payload: PartyUpdatePayload): Partial<Party> {
|
private mapToApiPayload(payload: PartyUpdatePayload): CreatePartyParams {
|
||||||
const mapped: any = {}
|
const mapped: any = {}
|
||||||
|
|
||||||
if (payload.name !== undefined) mapped.name = payload.name
|
if (payload.name !== undefined) mapped.name = payload.name
|
||||||
if (payload.description !== undefined) mapped.description = payload.description
|
if (payload.description !== undefined) mapped.description = payload.description
|
||||||
if (payload.element !== undefined) mapped.element = payload.element
|
if (payload.element !== undefined) mapped.element = payload.element
|
||||||
if (payload.raidId !== undefined) mapped.raid = { id: payload.raidId }
|
if (payload.raidId !== undefined) mapped.raidId = payload.raidId
|
||||||
if (payload.chargeAttack !== undefined) mapped.chargeAttack = payload.chargeAttack
|
if (payload.chargeAttack !== undefined) mapped.chargeAttack = payload.chargeAttack
|
||||||
if (payload.fullAuto !== undefined) mapped.fullAuto = payload.fullAuto
|
if (payload.fullAuto !== undefined) mapped.fullAuto = payload.fullAuto
|
||||||
if (payload.autoGuard !== undefined) mapped.autoGuard = payload.autoGuard
|
if (payload.autoGuard !== undefined) mapped.autoGuard = payload.autoGuard
|
||||||
|
|
@ -294,8 +294,16 @@ export class PartyService {
|
||||||
if (payload.buttonCount !== undefined) mapped.buttonCount = payload.buttonCount
|
if (payload.buttonCount !== undefined) mapped.buttonCount = payload.buttonCount
|
||||||
if (payload.chainCount !== undefined) mapped.chainCount = payload.chainCount
|
if (payload.chainCount !== undefined) mapped.chainCount = payload.chainCount
|
||||||
if (payload.turnCount !== undefined) mapped.turnCount = payload.turnCount
|
if (payload.turnCount !== undefined) mapped.turnCount = payload.turnCount
|
||||||
if (payload.jobId !== undefined) mapped.job = { id: payload.jobId }
|
if (payload.jobId !== undefined) mapped.jobId = payload.jobId
|
||||||
if (payload.visibility !== undefined) mapped.visibility = payload.visibility
|
if (payload.visibility !== undefined) {
|
||||||
|
// Convert number visibility to string
|
||||||
|
const visibilityMap: Record<number, 'public' | 'private' | 'unlisted'> = {
|
||||||
|
0: 'public',
|
||||||
|
1: 'private',
|
||||||
|
2: 'unlisted'
|
||||||
|
}
|
||||||
|
mapped.visibility = visibilityMap[payload.visibility] || 'public'
|
||||||
|
}
|
||||||
if (payload.localId !== undefined) mapped.localId = payload.localId
|
if (payload.localId !== undefined) mapped.localId = payload.localId
|
||||||
|
|
||||||
return mapped
|
return mapped
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ export function optionalProps<T extends Record<string, unknown>>(
|
||||||
const result: Partial<T> = {}
|
const result: Partial<T> = {}
|
||||||
for (const [key, value] of Object.entries(obj)) {
|
for (const [key, value] of Object.entries(obj)) {
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
result[key as keyof T] = value
|
result[key as keyof T] = value as T[keyof T]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue