uup
This commit is contained in:
61
app/types/auth.ts
Normal file
61
app/types/auth.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import type { User } from "@prisma/client";
|
||||
|
||||
// Authentication levels
|
||||
export const AUTH_LEVELS = {
|
||||
SUPERADMIN: 1,
|
||||
ADMIN: 2,
|
||||
USER: 3,
|
||||
} as const;
|
||||
|
||||
export type AuthLevel = typeof AUTH_LEVELS[keyof typeof AUTH_LEVELS];
|
||||
|
||||
// User status types
|
||||
export const USER_STATUS = {
|
||||
ACTIVE: "active",
|
||||
INACTIVE: "inactive",
|
||||
} as const;
|
||||
|
||||
export type UserStatus = typeof USER_STATUS[keyof typeof USER_STATUS];
|
||||
|
||||
// Authentication form data types
|
||||
export interface SignInFormData {
|
||||
usernameOrEmail: string;
|
||||
password: string;
|
||||
redirectTo?: string;
|
||||
}
|
||||
|
||||
export interface SignUpFormData {
|
||||
name: string;
|
||||
username: string;
|
||||
email: string;
|
||||
password: string;
|
||||
confirmPassword: string;
|
||||
}
|
||||
|
||||
// User data without sensitive information
|
||||
export type SafeUser = Omit<User, "password">;
|
||||
|
||||
// Authentication error types
|
||||
export interface AuthError {
|
||||
field?: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
// Authentication result types
|
||||
export interface AuthResult {
|
||||
success: boolean;
|
||||
user?: SafeUser;
|
||||
errors?: AuthError[];
|
||||
}
|
||||
|
||||
// Session data type
|
||||
export interface SessionData {
|
||||
userId: number;
|
||||
}
|
||||
|
||||
// Route protection types
|
||||
export interface RouteProtectionOptions {
|
||||
requiredAuthLevel?: AuthLevel;
|
||||
allowInactive?: boolean;
|
||||
redirectTo?: string;
|
||||
}
|
||||
290
app/types/database.ts
Normal file
290
app/types/database.ts
Normal file
@@ -0,0 +1,290 @@
|
||||
import type { User, Customer, Vehicle, MaintenanceVisit, MaintenanceType, Expense, Income, CarDataset, Settings } from '@prisma/client';
|
||||
|
||||
// Re-export Prisma types for easier imports
|
||||
export type {
|
||||
User,
|
||||
Customer,
|
||||
Vehicle,
|
||||
MaintenanceVisit,
|
||||
MaintenanceType,
|
||||
Expense,
|
||||
Income,
|
||||
CarDataset,
|
||||
Settings,
|
||||
} from '@prisma/client';
|
||||
|
||||
// Extended types with relationships
|
||||
export type UserWithoutPassword = Omit<User, 'password'>;
|
||||
|
||||
export type CustomerWithVehicles = Customer & {
|
||||
vehicles: Vehicle[];
|
||||
maintenanceVisits: (MaintenanceVisit & {
|
||||
vehicle: {
|
||||
id: number;
|
||||
plateNumber: string;
|
||||
manufacturer: string;
|
||||
model: string;
|
||||
year: number;
|
||||
};
|
||||
})[];
|
||||
};
|
||||
|
||||
export type VehicleWithOwner = Vehicle & {
|
||||
owner: Customer;
|
||||
};
|
||||
|
||||
export type VehicleWithRelations = Vehicle & {
|
||||
owner: Customer;
|
||||
maintenanceVisits: MaintenanceVisit[];
|
||||
};
|
||||
|
||||
// Maintenance job interface for JSON field
|
||||
export interface MaintenanceJob {
|
||||
typeId: number;
|
||||
job: string;
|
||||
cost: number;
|
||||
notes?: string;
|
||||
}
|
||||
|
||||
export type MaintenanceVisitWithRelations = MaintenanceVisit & {
|
||||
vehicle: Vehicle;
|
||||
customer: Customer;
|
||||
income: Income[];
|
||||
// maintenanceJobs will be parsed from JSON string
|
||||
};
|
||||
|
||||
export type IncomeWithVisit = Income & {
|
||||
maintenanceVisit: MaintenanceVisit;
|
||||
};
|
||||
|
||||
// Enums for form validation and type safety
|
||||
export const UserStatus = {
|
||||
ACTIVE: 'active',
|
||||
INACTIVE: 'inactive',
|
||||
} as const;
|
||||
|
||||
export const AuthLevel = {
|
||||
SUPERADMIN: 1,
|
||||
ADMIN: 2,
|
||||
USER: 3,
|
||||
} as const;
|
||||
|
||||
export const TransmissionType = {
|
||||
AUTOMATIC: 'Automatic',
|
||||
MANUAL: 'Manual',
|
||||
} as const;
|
||||
|
||||
export const FuelType = {
|
||||
GASOLINE: 'Gasoline',
|
||||
DIESEL: 'Diesel',
|
||||
HYBRID: 'Hybrid',
|
||||
MILD_HYBRID: 'Mild Hybrid',
|
||||
ELECTRIC: 'Electric',
|
||||
} as const;
|
||||
|
||||
export const UseType = {
|
||||
PERSONAL: 'personal',
|
||||
TAXI: 'taxi',
|
||||
APPS: 'apps',
|
||||
LOADING: 'loading',
|
||||
TRAVEL: 'travel',
|
||||
} as const;
|
||||
|
||||
export const PaymentStatus = {
|
||||
PENDING: 'pending',
|
||||
PAID: 'paid',
|
||||
PARTIAL: 'partial',
|
||||
CANCELLED: 'cancelled',
|
||||
} as const;
|
||||
|
||||
// Form data types for validation
|
||||
export interface CreateUserData {
|
||||
name: string;
|
||||
username: string;
|
||||
email: string;
|
||||
password: string;
|
||||
authLevel: number;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export interface UpdateUserData {
|
||||
name?: string;
|
||||
username?: string;
|
||||
email?: string;
|
||||
password?: string;
|
||||
authLevel?: number;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export interface CreateCustomerData {
|
||||
name: string;
|
||||
phone?: string;
|
||||
email?: string;
|
||||
address?: string;
|
||||
}
|
||||
|
||||
export interface UpdateCustomerData {
|
||||
name?: string;
|
||||
phone?: string;
|
||||
email?: string;
|
||||
address?: string;
|
||||
}
|
||||
|
||||
export interface CreateVehicleData {
|
||||
plateNumber: string;
|
||||
bodyType: string;
|
||||
manufacturer: string;
|
||||
model: string;
|
||||
trim?: string;
|
||||
year: number;
|
||||
transmission: string;
|
||||
fuel: string;
|
||||
cylinders?: number;
|
||||
engineDisplacement?: number;
|
||||
useType: string;
|
||||
ownerId: number;
|
||||
}
|
||||
|
||||
export interface UpdateVehicleData {
|
||||
plateNumber?: string;
|
||||
bodyType?: string;
|
||||
manufacturer?: string;
|
||||
model?: string;
|
||||
trim?: string;
|
||||
year?: number;
|
||||
transmission?: string;
|
||||
fuel?: string;
|
||||
cylinders?: number;
|
||||
engineDisplacement?: number;
|
||||
useType?: string;
|
||||
ownerId?: number;
|
||||
lastVisitDate?: Date;
|
||||
suggestedNextVisitDate?: Date;
|
||||
}
|
||||
|
||||
export interface CreateMaintenanceTypeData {
|
||||
name: string;
|
||||
description?: string;
|
||||
isActive?: boolean;
|
||||
}
|
||||
|
||||
export interface UpdateMaintenanceTypeData {
|
||||
name?: string;
|
||||
description?: string;
|
||||
isActive?: boolean;
|
||||
}
|
||||
|
||||
export interface CreateMaintenanceVisitData {
|
||||
vehicleId: number;
|
||||
customerId: number;
|
||||
maintenanceJobs: MaintenanceJob[];
|
||||
description: string;
|
||||
cost: number;
|
||||
paymentStatus?: string;
|
||||
kilometers: number;
|
||||
visitDate?: Date;
|
||||
nextVisitDelay: number;
|
||||
}
|
||||
|
||||
export interface UpdateMaintenanceVisitData {
|
||||
vehicleId?: number;
|
||||
customerId?: number;
|
||||
maintenanceJobs?: MaintenanceJob[];
|
||||
description?: string;
|
||||
cost?: number;
|
||||
paymentStatus?: string;
|
||||
kilometers?: number;
|
||||
visitDate?: Date;
|
||||
nextVisitDelay?: number;
|
||||
}
|
||||
|
||||
export interface CreateExpenseData {
|
||||
description: string;
|
||||
category: string;
|
||||
amount: number;
|
||||
expenseDate?: Date;
|
||||
}
|
||||
|
||||
export interface UpdateExpenseData {
|
||||
description?: string;
|
||||
category?: string;
|
||||
amount?: number;
|
||||
expenseDate?: Date;
|
||||
}
|
||||
|
||||
export interface CreateIncomeData {
|
||||
maintenanceVisitId: number;
|
||||
amount: number;
|
||||
incomeDate?: Date;
|
||||
}
|
||||
|
||||
export interface CreateCarDatasetData {
|
||||
manufacturer: string;
|
||||
model: string;
|
||||
bodyType: string;
|
||||
isActive?: boolean;
|
||||
}
|
||||
|
||||
export interface UpdateCarDatasetData {
|
||||
manufacturer?: string;
|
||||
model?: string;
|
||||
bodyType?: string;
|
||||
isActive?: boolean;
|
||||
}
|
||||
|
||||
// Utility types for API responses
|
||||
export interface ApiResponse<T = any> {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
error?: {
|
||||
code: string;
|
||||
message: string;
|
||||
details?: any;
|
||||
};
|
||||
}
|
||||
|
||||
export interface PaginatedResponse<T = any> {
|
||||
data: T[];
|
||||
pagination: {
|
||||
page: number;
|
||||
limit: number;
|
||||
total: number;
|
||||
totalPages: number;
|
||||
};
|
||||
}
|
||||
|
||||
// Search and filter types
|
||||
export interface SearchParams {
|
||||
query?: string;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
sortBy?: string;
|
||||
sortOrder?: 'asc' | 'desc';
|
||||
}
|
||||
|
||||
export interface CustomerSearchParams extends SearchParams {
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export interface VehicleSearchParams extends SearchParams {
|
||||
manufacturer?: string;
|
||||
year?: number;
|
||||
useType?: string;
|
||||
ownerId?: number;
|
||||
}
|
||||
|
||||
export interface MaintenanceVisitSearchParams extends SearchParams {
|
||||
vehicleId?: number;
|
||||
customerId?: number;
|
||||
dateFrom?: Date;
|
||||
dateTo?: Date;
|
||||
paymentStatus?: string;
|
||||
}
|
||||
|
||||
export interface FinancialSearchParams extends SearchParams {
|
||||
category?: string;
|
||||
dateFrom?: Date;
|
||||
dateTo?: Date;
|
||||
amountMin?: number;
|
||||
amountMax?: number;
|
||||
}
|
||||
Reference in New Issue
Block a user