Files
csgowtf/src/lib/schemas/player.schema.ts
vikingowl 8f3b652740 feat: Implement Phase 1 critical features and fix API integration
This commit completes the first phase of feature parity implementation and
resolves all API integration issues to match the backend API format.

## API Integration Fixes

- Remove all hardcoded default values from transformers (tick_rate, kast, player_count, steam_updated)
- Update TypeScript types to make fields optional where backend doesn't guarantee them
- Update Zod schemas to validate optional fields correctly
- Fix mock data to match real API response format (plain arrays, not wrapped objects)
- Update UI components to handle undefined values with proper fallbacks
- Add comprehensive API documentation for Match and Player endpoints

## Phase 1 Features Implemented (3/6)

### 1. Player Tracking System 
- Created TrackPlayerModal.svelte with auth code input
- Integrated track/untrack player API endpoints
- Added UI for providing optional share code
- Displays tracked status on player profiles
- Full validation and error handling

### 2. Share Code Parsing 
- Created ShareCodeInput.svelte component
- Added to matches page for easy match submission
- Real-time validation of share code format
- Parse status feedback with loading states
- Auto-redirect to match page on success

### 3. VAC/Game Ban Status 
- Added VAC and game ban count/date fields to Player type
- Display status badges on player profile pages
- Show ban count and date when available
- Visual indicators using DaisyUI badge components

## Component Improvements

- Modal.svelte: Added Svelte 5 Snippet types, actions slot support
- ThemeToggle.svelte: Removed deprecated svelte:component usage
- Tooltip.svelte: Fixed type safety with Snippet type
- All new components follow Svelte 5 runes pattern ($state, $derived, $bindable)

## Type Safety & Linting

- Fixed all ESLint errors (any types → proper types)
- Fixed form label accessibility issues
- Replaced error: any with error: unknown + proper type guards
- Added Snippet type imports where needed
- Updated all catch blocks to use instanceof Error checks

## Static Assets

- Migrated all files from public/ to static/ directory per SvelteKit best practices
- Moved 200+ map icons, screenshots, and other assets
- Updated all import paths to use /images/ (served from static/)

## Documentation

- Created IMPLEMENTATION_STATUS.md tracking all 15 missing features
- Updated API.md with optional field annotations
- Created MATCHES_API.md with comprehensive endpoint documentation
- Added inline comments marking optional vs required fields

## Testing

- Updated mock fixtures to remove default values
- Fixed mock handlers to return plain arrays like real API
- Ensured all components handle undefined gracefully

## Remaining Phase 1 Tasks

- [ ] Add VAC status column to match scoreboard
- [ ] Create weapons statistics tab for matches
- [ ] Implement recently visited players on home page

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-12 19:31:18 +01:00

90 lines
3.0 KiB
TypeScript

import { z } from 'zod';
import { matchSchema, matchPlayerSchema } from './match.schema';
/**
* Zod schemas for Player data models
*/
/** Player schema */
export const playerSchema = z.object({
id: z.string().min(1), // Steam ID uint64 as string to preserve precision
name: z.string().min(1),
avatar: z.string().url(),
vanity_url: z.string().optional(),
vanity_url_real: z.string().optional(),
steam_updated: z.string().datetime().optional(),
profile_created: z.string().datetime().optional(),
wins: z.number().int().nonnegative().optional(),
losses: z.number().int().nonnegative().optional(),
// Also support backend's typo "looses"
looses: z.number().int().nonnegative().optional(),
ties: z.number().int().nonnegative().optional(),
vac_count: z.number().int().nonnegative().optional(),
vac_date: z.string().datetime().nullable().optional(),
game_ban_count: z.number().int().nonnegative().optional(),
game_ban_date: z.string().datetime().nullable().optional(),
oldest_sharecode_seen: z.string().optional(),
tracked: z.boolean().optional(),
matches: z
.array(
matchSchema.extend({
stats: matchPlayerSchema
})
)
.optional()
});
/** Transform player data to normalize "looses" to "losses" */
export const normalizePlayerData = (data: z.infer<typeof playerSchema>) => {
if (data.looses !== undefined && data.losses === undefined) {
return { ...data, losses: data.looses };
}
return data;
};
/** PlayerMeta schema */
export const playerMetaSchema = z.object({
id: z.number().positive(),
name: z.string().min(1),
avatar: z.string().url(),
recent_matches: z.number().int().nonnegative(),
last_match_date: z.string().datetime(),
avg_kills: z.number().nonnegative(),
avg_deaths: z.number().nonnegative(),
avg_kast: z.number().nonnegative(),
win_rate: z.number().nonnegative()
});
/** PlayerProfile schema (extended with calculated stats) */
export const playerProfileSchema = playerSchema.extend({
total_matches: z.number().int().nonnegative(),
kd_ratio: z.number().nonnegative(),
win_rate: z.number().nonnegative(),
avg_headshot_pct: z.number().nonnegative(),
avg_kast: z.number().nonnegative(),
current_rating: z.number().int().min(0).max(30000).optional(),
peak_rating: z.number().int().min(0).max(30000).optional()
});
/** Parser functions */
export const parsePlayer = (data: unknown) => {
const parsed = playerSchema.parse(data);
return normalizePlayerData(parsed);
};
export const parsePlayerSafe = (data: unknown) => {
const result = playerSchema.safeParse(data);
if (result.success) {
return { ...result, data: normalizePlayerData(result.data) };
}
return result;
};
export const parsePlayerMeta = (data: unknown) => playerMetaSchema.parse(data);
export const parsePlayerProfile = (data: unknown) => playerProfileSchema.parse(data);
/** Infer TypeScript types */
export type PlayerSchema = z.infer<typeof playerSchema>;
export type PlayerMetaSchema = z.infer<typeof playerMetaSchema>;
export type PlayerProfileSchema = z.infer<typeof playerProfileSchema>;