-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.ts
More file actions
149 lines (139 loc) · 4.99 KB
/
Copy pathschema.ts
File metadata and controls
149 lines (139 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { pgTable, text, serial, integer, boolean, timestamp, jsonb } from "drizzle-orm/pg-core";
import { createInsertSchema } from "drizzle-zod";
import { z } from "zod";
// Admin credentials will be seeded
export const admins = pgTable("admins", {
id: serial("id").primaryKey(),
username: text("username").notNull().unique(),
password: text("password").notNull(),
});
export const sports = pgTable("sports", {
id: serial("id").primaryKey(),
name: text("name").notNull().unique(),
icon: text("icon"), // Lucide icon name
});
export const teams = pgTable("teams", {
id: serial("id").primaryKey(),
name: text("name").notNull(), // Department name
sportId: integer("sport_id").references(() => sports.id),
players: jsonb("players").$type<string[]>().default([]), // List of player names
});
export const matches = pgTable("matches", {
id: serial("id").primaryKey(),
sportId: integer("sport_id").references(() => sports.id).notNull(),
teamA: text("team_a").notNull(),
teamB: text("team_b").notNull(),
date: timestamp("date").notNull(),
status: text("status").notNull().default("upcoming"), // upcoming, live, completed
scoreA: text("score_a").default("0"),
scoreB: text("score_b").default("0"),
winner: text("winner"), // Team name or "draw"
// Flexible details for different sports
details: jsonb("details").$type<{
overs?: string;
wicketA?: string;
wicketB?: string;
currentBatter?: string;
currentBowler?: string;
setScores?: string[];
description?: string;
// Cricket Scorecard Stats
currentInning?: number; // 1 or 2
// Live batting stats
striker?: {
playerName: string;
runs: number;
balls: number;
fours: number;
sixes: number;
};
nonStriker?: {
playerName: string;
runs: number;
balls: number;
fours: number;
sixes: number;
};
// Live bowling stats
currentBowlerStats?: {
playerName: string;
overs: string;
runs: number;
wickets: number;
wides: number;
noBalls: number;
};
innings?: {
team: string;
battingStats: {
playerName: string;
runs: number;
balls: number;
fours: number;
sixes: number;
isOut: boolean;
}[];
bowlingStats: {
playerName: string;
overs: string;
wickets: number;
runs: number;
wides: number;
noBalls: number;
}[];
}[];
}>(),
});
// For Cricket specific requirements
export const cricketStats = pgTable("cricket_stats", {
id: serial("id").primaryKey(),
playerName: text("player_name").notNull(),
teamName: text("team_name").notNull(),
runs: integer("runs").default(0),
wickets: integer("wickets").default(0),
matchesPlayed: integer("matches_played").default(0),
isOrangeCap: boolean("is_orange_cap").default(false),
isPurpleCap: boolean("is_purple_cap").default(false),
});
export const pointsTable = pgTable("points_table", {
id: serial("id").primaryKey(),
sportId: integer("sport_id").references(() => sports.id),
teamName: text("team_name").notNull(),
matches: integer("matches").default(0),
won: integer("won").default(0),
lost: integer("lost").default(0),
points: integer("points").default(0),
nrr: text("nrr").default("0.000"), // Net Run Rate for cricket
});
// GC Points Table (Grand Championship Points across all departments)
export const gcPoints = pgTable("gc_points", {
id: serial("id").primaryKey(),
rank: integer("rank").notNull(),
department: text("department").notNull().unique(),
winner: integer("winner").default(0), // Number of wins
runnerUp: integer("runner_up").default(0), // Number of runner-up finishes
totalPoints: integer("total_points").default(0),
});
// Schemas
export const insertAdminSchema = createInsertSchema(admins);
export const insertSportSchema = createInsertSchema(sports);
export const insertTeamSchema = createInsertSchema(teams);
export const insertMatchSchema = createInsertSchema(matches);
export const insertCricketStatsSchema = createInsertSchema(cricketStats);
export const insertPointsTableSchema = createInsertSchema(pointsTable);
export const insertGCPointsSchema = createInsertSchema(gcPoints);
// Types
export type Admin = typeof admins.$inferSelect;
export type Sport = typeof sports.$inferSelect;
export type Team = typeof teams.$inferSelect;
export type Match = typeof matches.$inferSelect;
export type CricketStat = typeof cricketStats.$inferSelect;
export type PointsEntry = typeof pointsTable.$inferSelect;
export type GCPointsEntry = typeof gcPoints.$inferSelect;
export type InsertAdmin = z.infer<typeof insertAdminSchema>;
export type InsertSport = z.infer<typeof insertSportSchema>;
export type InsertTeam = z.infer<typeof insertTeamSchema>;
export type InsertMatch = z.infer<typeof insertMatchSchema>;
export type InsertCricketStat = z.infer<typeof insertCricketStatsSchema>;
export type InsertPointsEntry = z.infer<typeof insertPointsTableSchema>;
export type InsertGCPointsEntry = z.infer<typeof insertGCPointsSchema>;