use numeric visibility values to match rails api
This commit is contained in:
parent
234b7809fe
commit
b88fbf60f6
6 changed files with 18 additions and 46 deletions
|
|
@ -18,7 +18,7 @@ describe('PartyAdapter', () => {
|
|||
shortcode: 'ABC123',
|
||||
name: 'Test Party',
|
||||
description: 'Test description',
|
||||
visibility: 'public',
|
||||
visibility: 1,
|
||||
user: {
|
||||
id: 'user-1',
|
||||
username: 'testuser'
|
||||
|
|
@ -75,7 +75,7 @@ describe('PartyAdapter', () => {
|
|||
const result = await adapter.create({
|
||||
name: 'Test Party',
|
||||
description: 'Test description',
|
||||
visibility: 'public'
|
||||
visibility: 1
|
||||
})
|
||||
|
||||
expect(result).toEqual(mockParty)
|
||||
|
|
@ -87,7 +87,7 @@ describe('PartyAdapter', () => {
|
|||
party: {
|
||||
name: 'Test Party',
|
||||
description: 'Test description',
|
||||
visibility: 'public'
|
||||
visibility: 1
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
@ -187,7 +187,7 @@ describe('PartyAdapter', () => {
|
|||
username: 'testuser',
|
||||
page: 1,
|
||||
per: 20,
|
||||
visibility: 'public',
|
||||
visibility: 1,
|
||||
raidId: 'raid-1'
|
||||
})
|
||||
|
||||
|
|
@ -203,7 +203,7 @@ describe('PartyAdapter', () => {
|
|||
const callUrl = (global.fetch as any).mock.calls[0][0]
|
||||
expect(callUrl).toContain('page=1')
|
||||
expect(callUrl).toContain('per=20')
|
||||
expect(callUrl).toContain('visibility=public')
|
||||
expect(callUrl).toContain('visibility=1')
|
||||
expect(callUrl).toContain('raid_id=raid-1')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ describe('UserAdapter', () => {
|
|||
shortcode: 'abc123',
|
||||
name: 'Fire Team',
|
||||
user: mockUser,
|
||||
visibility: 'public',
|
||||
visibility: 1,
|
||||
element: 1,
|
||||
characters: [],
|
||||
weapons: [],
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import type { AdapterOptions, PaginatedResponse } from './types'
|
|||
import { DEFAULT_ADAPTER_CONFIG } from './config'
|
||||
import type { Party, GridWeapon, GridCharacter, GridSummon } from '$lib/types/api/party'
|
||||
import type { PartyShare } from '$lib/types/api/partyShare'
|
||||
import type { PartyVisibility } from '$lib/types/visibility'
|
||||
|
||||
/**
|
||||
* Parameters for creating a new party
|
||||
|
|
@ -20,7 +21,7 @@ import type { PartyShare } from '$lib/types/api/partyShare'
|
|||
export interface CreatePartyParams {
|
||||
name?: string | undefined
|
||||
description?: string | undefined
|
||||
visibility?: 'public' | 'private' | 'unlisted' | undefined
|
||||
visibility?: PartyVisibility | undefined
|
||||
jobId?: string | undefined
|
||||
raidId?: string | null | undefined
|
||||
guidebookId?: string | undefined
|
||||
|
|
@ -58,7 +59,7 @@ export interface ListUserPartiesParams {
|
|||
username: string
|
||||
page?: number
|
||||
per?: number
|
||||
visibility?: 'public' | 'private' | 'unlisted' | 'all'
|
||||
visibility?: PartyVisibility | 'all'
|
||||
raidId?: string
|
||||
characterId?: string
|
||||
weaponId?: string
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ const MinimalScalarsSchema = z
|
|||
turnCount: z.number().nullish().optional(),
|
||||
summonCount: z.number().nullish().optional(),
|
||||
videoUrl: z.string().nullish().optional(),
|
||||
visibility: z.enum(['public', 'private', 'unlisted']).nullish().optional()
|
||||
visibility: z.union([z.literal(1), z.literal(2), z.literal(3)]).nullish().optional()
|
||||
})
|
||||
.partial()
|
||||
|
||||
|
|
@ -391,7 +391,7 @@ export const PartySchemaRaw = z.object({
|
|||
name: z.string().nullish(),
|
||||
description: z.string().nullish(),
|
||||
shortcode: z.string(),
|
||||
visibility: z.enum(['public', 'private', 'unlisted']).nullish().default('private'),
|
||||
visibility: z.union([z.literal(1), z.literal(2), z.literal(3)]).nullish().default(3),
|
||||
element: z.number().nullish(),
|
||||
|
||||
// Battle settings
|
||||
|
|
|
|||
|
|
@ -453,7 +453,7 @@
|
|||
const initialValues: PartyEditValues = {
|
||||
name: party.name ?? '',
|
||||
description: party.description ?? null,
|
||||
visibility: party.visibility ?? 'public',
|
||||
visibility: party.visibility ?? 1,
|
||||
sharedWithCrew: isSharedWithCrew,
|
||||
fullAuto: party.fullAuto ?? false,
|
||||
autoGuard: party.autoGuard ?? false,
|
||||
|
|
|
|||
|
|
@ -2,43 +2,14 @@
|
|||
* Party visibility values
|
||||
*
|
||||
* These determine who can view a party:
|
||||
* - public: Anyone can see it
|
||||
* - private: Only the owner can see it
|
||||
* - unlisted: Anyone with the link can see it (not in public listings)
|
||||
* - 1 (PUBLIC): Anyone can see it
|
||||
* - 2 (UNLISTED): Anyone with the link can see it (not in public listings)
|
||||
* - 3 (PRIVATE): Only the owner can see it
|
||||
*/
|
||||
export const PartyVisibility = {
|
||||
PUBLIC: 'public',
|
||||
PRIVATE: 'private',
|
||||
UNLISTED: 'unlisted'
|
||||
PUBLIC: 1,
|
||||
UNLISTED: 2,
|
||||
PRIVATE: 3
|
||||
} as const
|
||||
|
||||
export type PartyVisibility = (typeof PartyVisibility)[keyof typeof PartyVisibility]
|
||||
|
||||
/**
|
||||
* Legacy mapping from numeric visibility values to string literals
|
||||
* Used for backward compatibility when reading from API
|
||||
*
|
||||
* @deprecated New code should use string literals directly
|
||||
*/
|
||||
export function numericToVisibility(value: number): PartyVisibility {
|
||||
const map: Record<number, PartyVisibility> = {
|
||||
0: PartyVisibility.PUBLIC,
|
||||
1: PartyVisibility.PRIVATE,
|
||||
2: PartyVisibility.UNLISTED
|
||||
}
|
||||
return map[value] ?? PartyVisibility.PUBLIC
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert visibility string to numeric value for API compatibility
|
||||
*
|
||||
* @deprecated Should be removed once API accepts string literals
|
||||
*/
|
||||
export function visibilityToNumeric(value: PartyVisibility): number {
|
||||
const map: Record<PartyVisibility, number> = {
|
||||
[PartyVisibility.PUBLIC]: 0,
|
||||
[PartyVisibility.PRIVATE]: 1,
|
||||
[PartyVisibility.UNLISTED]: 2
|
||||
}
|
||||
return map[value]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue