init commit
This commit is contained in:
70
src/models/User.ts
Normal file
70
src/models/User.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
export interface UserData {
|
||||
id: string;
|
||||
telegramId: number;
|
||||
username?: string;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
languageCode?: string;
|
||||
isActive: boolean;
|
||||
createdAt: Date;
|
||||
lastActiveAt: Date;
|
||||
}
|
||||
|
||||
export class User {
|
||||
id: string;
|
||||
telegramId: number;
|
||||
username?: string;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
languageCode?: string;
|
||||
isActive: boolean;
|
||||
createdAt: Date;
|
||||
lastActiveAt: Date;
|
||||
|
||||
constructor(data: UserData) {
|
||||
this.id = data.id;
|
||||
this.telegramId = data.telegramId;
|
||||
this.username = data.username;
|
||||
this.firstName = data.firstName;
|
||||
this.lastName = data.lastName;
|
||||
this.languageCode = data.languageCode || 'en';
|
||||
this.isActive = data.isActive;
|
||||
this.createdAt = data.createdAt;
|
||||
this.lastActiveAt = data.lastActiveAt;
|
||||
}
|
||||
|
||||
// Метод для получения информации о пользователе
|
||||
getUserInfo() {
|
||||
return {
|
||||
id: this.id,
|
||||
telegramId: this.telegramId,
|
||||
username: this.username,
|
||||
firstName: this.firstName,
|
||||
lastName: this.lastName,
|
||||
fullName: this.getFullName(),
|
||||
isActive: this.isActive
|
||||
};
|
||||
}
|
||||
|
||||
// Получить полное имя пользователя
|
||||
getFullName(): string {
|
||||
const parts = [this.firstName, this.lastName].filter(Boolean);
|
||||
return parts.length > 0 ? parts.join(' ') : this.username || `User ${this.telegramId}`;
|
||||
}
|
||||
|
||||
// Обновить время последней активности
|
||||
updateLastActive(): void {
|
||||
this.lastActiveAt = new Date();
|
||||
}
|
||||
|
||||
// Деактивировать пользователя
|
||||
deactivate(): void {
|
||||
this.isActive = false;
|
||||
}
|
||||
|
||||
// Активировать пользователя
|
||||
activate(): void {
|
||||
this.isActive = true;
|
||||
this.updateLastActive();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user