181 lines
3.0 KiB
TypeScript
181 lines
3.0 KiB
TypeScript
/**
|
|
* Core TypeScript types for the task-based earning platform
|
|
*/
|
|
|
|
// Enums
|
|
export enum TaskType {
|
|
CHECKIN = 'checkin',
|
|
AD = 'ad',
|
|
SURVEY = 'survey',
|
|
REFERRAL = 'referral',
|
|
QUIZ = 'quiz',
|
|
VIDEO = 'video',
|
|
READING = 'reading'
|
|
}
|
|
|
|
export enum RequirementType {
|
|
POINTS_TOTAL = 'points_total',
|
|
TASKS_COMPLETED = 'tasks_completed',
|
|
STREAK_DAYS = 'streak_days',
|
|
REFERRALS = 'referrals'
|
|
}
|
|
|
|
export enum TransactionType {
|
|
EARNED = 'earned',
|
|
SPENT = 'spent'
|
|
}
|
|
|
|
// User related types
|
|
export interface User {
|
|
id: string;
|
|
email: string;
|
|
passwordHash: string;
|
|
name: string;
|
|
createdAt: Date;
|
|
updatedAt: Date;
|
|
}
|
|
|
|
export interface UserProfile extends Omit<User, 'passwordHash'> {
|
|
pointsBalance: number;
|
|
tasksCompleted: number;
|
|
badgesCount: number;
|
|
}
|
|
|
|
// Points and Transactions
|
|
export interface Transaction {
|
|
id: string;
|
|
userId: string;
|
|
amount: number;
|
|
type: TransactionType;
|
|
source: string;
|
|
createdAt: Date;
|
|
}
|
|
|
|
// Tasks
|
|
export interface Task {
|
|
id: string;
|
|
type: TaskType;
|
|
title: string;
|
|
description: string;
|
|
pointsReward: number;
|
|
isActive: boolean;
|
|
createdAt?: Date;
|
|
updatedAt?: Date;
|
|
}
|
|
|
|
export interface UserTask {
|
|
id: string;
|
|
userId: string;
|
|
taskId: string;
|
|
completedAt: Date;
|
|
pointsEarned: number;
|
|
}
|
|
|
|
// Badges
|
|
export interface Badge {
|
|
id: string;
|
|
name: string;
|
|
description: string;
|
|
icon: string;
|
|
requirementType: RequirementType;
|
|
requirementValue: number;
|
|
}
|
|
|
|
export interface UserBadge {
|
|
id: string;
|
|
userId: string;
|
|
badgeId: string;
|
|
earnedAt: Date;
|
|
}
|
|
|
|
// Quiz
|
|
export interface Quiz {
|
|
id: string;
|
|
taskId: string;
|
|
question: string;
|
|
options: string[];
|
|
correctAnswer: number;
|
|
}
|
|
|
|
export interface QuizAttempt {
|
|
id: string;
|
|
userId: string;
|
|
quizId: string;
|
|
selectedAnswer: number;
|
|
isCorrect: boolean;
|
|
pointsEarned: number;
|
|
completedAt: Date;
|
|
}
|
|
|
|
// Referrals
|
|
export interface Referral {
|
|
id: string;
|
|
referrerId: string;
|
|
referredId: string;
|
|
bonusPoints: number;
|
|
createdAt: Date;
|
|
}
|
|
|
|
// API Response Types
|
|
export interface ApiResponse<T = unknown> {
|
|
success: boolean;
|
|
data?: T;
|
|
error?: string;
|
|
message?: string;
|
|
}
|
|
|
|
export interface AuthResponse {
|
|
user: UserProfile;
|
|
token: string;
|
|
}
|
|
|
|
export interface PointsResponse {
|
|
balance: number;
|
|
transactions: Transaction[];
|
|
}
|
|
|
|
export interface TasksResponse {
|
|
available: Task[];
|
|
completed: UserTask[];
|
|
}
|
|
|
|
export interface BadgesResponse {
|
|
earned: (UserBadge & { badge: Badge })[];
|
|
available: Badge[];
|
|
}
|
|
|
|
export interface LeaderboardEntry {
|
|
userId: string;
|
|
userName: string;
|
|
points: number;
|
|
rank: number;
|
|
tasksCompleted: number;
|
|
badgesEarned: number;
|
|
}
|
|
|
|
export interface LeaderboardResponse {
|
|
entries: LeaderboardEntry[];
|
|
userRank?: LeaderboardEntry;
|
|
}
|
|
|
|
// Request Types
|
|
export interface LoginRequest {
|
|
email: string;
|
|
password: string;
|
|
}
|
|
|
|
export interface RegisterRequest {
|
|
email: string;
|
|
password: string;
|
|
name: string;
|
|
}
|
|
|
|
export interface CompleteTaskRequest {
|
|
taskId: string;
|
|
quizAnswer?: number;
|
|
}
|
|
|
|
export interface CreateReferralRequest {
|
|
referredEmail: string;
|
|
}
|