refactor: unify visibility types to string literals
Changed from numeric (0/1/2) to string literals ('public'/'private'/'unlisted')
- Created PartyVisibility type with const assertion
- Updated Party and PartyPreview interfaces
- Updated PartyUpdatePayload interface
- Updated Zod schemas for validation
- Updated test mocks to use string literals
- Added deprecated conversion helpers for backward compat
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
ca16ca145b
commit
c074ea8bda
6 changed files with 52 additions and 16 deletions
|
|
@ -18,7 +18,7 @@ describe('PartyAdapter', () => {
|
||||||
shortcode: 'ABC123',
|
shortcode: 'ABC123',
|
||||||
name: 'Test Party',
|
name: 'Test Party',
|
||||||
description: 'Test description',
|
description: 'Test description',
|
||||||
visibility: 0,
|
visibility: 'public',
|
||||||
user: {
|
user: {
|
||||||
id: 'user-1',
|
id: 'user-1',
|
||||||
username: 'testuser'
|
username: 'testuser'
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ describe('UserAdapter', () => {
|
||||||
shortcode: 'abc123',
|
shortcode: 'abc123',
|
||||||
name: 'Fire Team',
|
name: 'Fire Team',
|
||||||
user: mockUser,
|
user: mockUser,
|
||||||
visibility: 0,
|
visibility: 'public',
|
||||||
element: 1,
|
element: 1,
|
||||||
characters: [],
|
characters: [],
|
||||||
weapons: [],
|
weapons: [],
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ const MinimalScalarsSchema = z
|
||||||
buttonCount: z.number().nullish().optional(),
|
buttonCount: z.number().nullish().optional(),
|
||||||
chainCount: z.number().nullish().optional(),
|
chainCount: z.number().nullish().optional(),
|
||||||
turnCount: z.number().nullish().optional(),
|
turnCount: z.number().nullish().optional(),
|
||||||
visibility: z.number().nullish().optional()
|
visibility: z.enum(['public', 'private', 'unlisted']).nullish().optional()
|
||||||
})
|
})
|
||||||
.partial()
|
.partial()
|
||||||
|
|
||||||
|
|
@ -344,7 +344,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.number().nullish().default(1),
|
visibility: z.enum(['public', 'private', 'unlisted']).nullish().default('private'),
|
||||||
element: z.number().nullish(),
|
element: z.number().nullish(),
|
||||||
|
|
||||||
// Battle settings
|
// Battle settings
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ export interface PartyUpdatePayload {
|
||||||
chainCount?: number | null
|
chainCount?: number | null
|
||||||
turnCount?: number | null
|
turnCount?: number | null
|
||||||
jobId?: string
|
jobId?: string
|
||||||
visibility?: number
|
visibility?: import('$lib/types/visibility').PartyVisibility
|
||||||
localId?: string
|
localId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -295,15 +295,7 @@ export class PartyService {
|
||||||
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.jobId = payload.jobId
|
if (payload.jobId !== undefined) mapped.jobId = payload.jobId
|
||||||
if (payload.visibility !== undefined) {
|
if (payload.visibility !== undefined) mapped.visibility = payload.visibility
|
||||||
// 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
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ export interface Party {
|
||||||
buttonCount?: number
|
buttonCount?: number
|
||||||
turnCount?: number
|
turnCount?: number
|
||||||
chainCount?: number
|
chainCount?: number
|
||||||
visibility?: number
|
visibility?: import('$lib/types/visibility').PartyVisibility
|
||||||
element?: number
|
element?: number
|
||||||
favorited?: boolean
|
favorited?: boolean
|
||||||
extra?: boolean
|
extra?: boolean
|
||||||
|
|
@ -125,7 +125,7 @@ export interface PartyPreview {
|
||||||
shortcode: string
|
shortcode: string
|
||||||
name?: string
|
name?: string
|
||||||
favorited?: boolean
|
favorited?: boolean
|
||||||
visibility?: number
|
visibility?: import('$lib/types/visibility').PartyVisibility
|
||||||
raid?: {
|
raid?: {
|
||||||
name: { en: string; ja: string }
|
name: { en: string; ja: string }
|
||||||
group?: {
|
group?: {
|
||||||
|
|
|
||||||
44
src/lib/types/visibility.ts
Normal file
44
src/lib/types/visibility.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
/**
|
||||||
|
* 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)
|
||||||
|
*/
|
||||||
|
export const PartyVisibility = {
|
||||||
|
PUBLIC: 'public',
|
||||||
|
PRIVATE: 'private',
|
||||||
|
UNLISTED: 'unlisted'
|
||||||
|
} 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