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',
|
shortcode: 'ABC123',
|
||||||
name: 'Test Party',
|
name: 'Test Party',
|
||||||
description: 'Test description',
|
description: 'Test description',
|
||||||
visibility: 'public',
|
visibility: 1,
|
||||||
user: {
|
user: {
|
||||||
id: 'user-1',
|
id: 'user-1',
|
||||||
username: 'testuser'
|
username: 'testuser'
|
||||||
|
|
@ -75,7 +75,7 @@ describe('PartyAdapter', () => {
|
||||||
const result = await adapter.create({
|
const result = await adapter.create({
|
||||||
name: 'Test Party',
|
name: 'Test Party',
|
||||||
description: 'Test description',
|
description: 'Test description',
|
||||||
visibility: 'public'
|
visibility: 1
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result).toEqual(mockParty)
|
expect(result).toEqual(mockParty)
|
||||||
|
|
@ -87,7 +87,7 @@ describe('PartyAdapter', () => {
|
||||||
party: {
|
party: {
|
||||||
name: 'Test Party',
|
name: 'Test Party',
|
||||||
description: 'Test description',
|
description: 'Test description',
|
||||||
visibility: 'public'
|
visibility: 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -187,7 +187,7 @@ describe('PartyAdapter', () => {
|
||||||
username: 'testuser',
|
username: 'testuser',
|
||||||
page: 1,
|
page: 1,
|
||||||
per: 20,
|
per: 20,
|
||||||
visibility: 'public',
|
visibility: 1,
|
||||||
raidId: 'raid-1'
|
raidId: 'raid-1'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -203,7 +203,7 @@ describe('PartyAdapter', () => {
|
||||||
const callUrl = (global.fetch as any).mock.calls[0][0]
|
const callUrl = (global.fetch as any).mock.calls[0][0]
|
||||||
expect(callUrl).toContain('page=1')
|
expect(callUrl).toContain('page=1')
|
||||||
expect(callUrl).toContain('per=20')
|
expect(callUrl).toContain('per=20')
|
||||||
expect(callUrl).toContain('visibility=public')
|
expect(callUrl).toContain('visibility=1')
|
||||||
expect(callUrl).toContain('raid_id=raid-1')
|
expect(callUrl).toContain('raid_id=raid-1')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ describe('UserAdapter', () => {
|
||||||
shortcode: 'abc123',
|
shortcode: 'abc123',
|
||||||
name: 'Fire Team',
|
name: 'Fire Team',
|
||||||
user: mockUser,
|
user: mockUser,
|
||||||
visibility: 'public',
|
visibility: 1,
|
||||||
element: 1,
|
element: 1,
|
||||||
characters: [],
|
characters: [],
|
||||||
weapons: [],
|
weapons: [],
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import type { AdapterOptions, PaginatedResponse } from './types'
|
||||||
import { DEFAULT_ADAPTER_CONFIG } from './config'
|
import { DEFAULT_ADAPTER_CONFIG } from './config'
|
||||||
import type { Party, GridWeapon, GridCharacter, GridSummon } from '$lib/types/api/party'
|
import type { Party, GridWeapon, GridCharacter, GridSummon } from '$lib/types/api/party'
|
||||||
import type { PartyShare } from '$lib/types/api/partyShare'
|
import type { PartyShare } from '$lib/types/api/partyShare'
|
||||||
|
import type { PartyVisibility } from '$lib/types/visibility'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameters for creating a new party
|
* Parameters for creating a new party
|
||||||
|
|
@ -20,7 +21,7 @@ import type { PartyShare } from '$lib/types/api/partyShare'
|
||||||
export interface CreatePartyParams {
|
export interface CreatePartyParams {
|
||||||
name?: string | undefined
|
name?: string | undefined
|
||||||
description?: string | undefined
|
description?: string | undefined
|
||||||
visibility?: 'public' | 'private' | 'unlisted' | undefined
|
visibility?: PartyVisibility | undefined
|
||||||
jobId?: string | undefined
|
jobId?: string | undefined
|
||||||
raidId?: string | null | undefined
|
raidId?: string | null | undefined
|
||||||
guidebookId?: string | undefined
|
guidebookId?: string | undefined
|
||||||
|
|
@ -58,7 +59,7 @@ export interface ListUserPartiesParams {
|
||||||
username: string
|
username: string
|
||||||
page?: number
|
page?: number
|
||||||
per?: number
|
per?: number
|
||||||
visibility?: 'public' | 'private' | 'unlisted' | 'all'
|
visibility?: PartyVisibility | 'all'
|
||||||
raidId?: string
|
raidId?: string
|
||||||
characterId?: string
|
characterId?: string
|
||||||
weaponId?: string
|
weaponId?: string
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ const MinimalScalarsSchema = z
|
||||||
turnCount: z.number().nullish().optional(),
|
turnCount: z.number().nullish().optional(),
|
||||||
summonCount: z.number().nullish().optional(),
|
summonCount: z.number().nullish().optional(),
|
||||||
videoUrl: z.string().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()
|
.partial()
|
||||||
|
|
||||||
|
|
@ -391,7 +391,7 @@ export const PartySchemaRaw = z.object({
|
||||||
name: z.string().nullish(),
|
name: z.string().nullish(),
|
||||||
description: z.string().nullish(),
|
description: z.string().nullish(),
|
||||||
shortcode: z.string(),
|
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(),
|
element: z.number().nullish(),
|
||||||
|
|
||||||
// Battle settings
|
// Battle settings
|
||||||
|
|
|
||||||
|
|
@ -453,7 +453,7 @@
|
||||||
const initialValues: PartyEditValues = {
|
const initialValues: PartyEditValues = {
|
||||||
name: party.name ?? '',
|
name: party.name ?? '',
|
||||||
description: party.description ?? null,
|
description: party.description ?? null,
|
||||||
visibility: party.visibility ?? 'public',
|
visibility: party.visibility ?? 1,
|
||||||
sharedWithCrew: isSharedWithCrew,
|
sharedWithCrew: isSharedWithCrew,
|
||||||
fullAuto: party.fullAuto ?? false,
|
fullAuto: party.fullAuto ?? false,
|
||||||
autoGuard: party.autoGuard ?? false,
|
autoGuard: party.autoGuard ?? false,
|
||||||
|
|
|
||||||
|
|
@ -2,43 +2,14 @@
|
||||||
* Party visibility values
|
* Party visibility values
|
||||||
*
|
*
|
||||||
* These determine who can view a party:
|
* These determine who can view a party:
|
||||||
* - public: Anyone can see it
|
* - 1 (PUBLIC): Anyone can see it
|
||||||
* - private: Only the owner can see it
|
* - 2 (UNLISTED): Anyone with the link can see it (not in public listings)
|
||||||
* - unlisted: Anyone with the link can see it (not in public listings)
|
* - 3 (PRIVATE): Only the owner can see it
|
||||||
*/
|
*/
|
||||||
export const PartyVisibility = {
|
export const PartyVisibility = {
|
||||||
PUBLIC: 'public',
|
PUBLIC: 1,
|
||||||
PRIVATE: 'private',
|
UNLISTED: 2,
|
||||||
UNLISTED: 'unlisted'
|
PRIVATE: 3
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
export type PartyVisibility = (typeof PartyVisibility)[keyof typeof PartyVisibility]
|
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