save before flutter upgrade

This commit is contained in:
Abraham
2025-07-15 16:40:14 -07:00
commit 813c586a1c
197 changed files with 11144 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
import 'dart:convert';
class Role {
Role({
required this.name,
required this.roleId,
required this.permissions,
});
String name;
int roleId;
Permissions permissions;
factory Role.fromJson(String str) => Role.fromMap(json.decode(str));
factory Role.fromMap(Map<String, dynamic> json) => Role(
name: json["name"],
roleId: json["role_id"],
permissions: Permissions.fromMap(json["permissions"]),
);
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is Role && other.name == name && other.roleId == roleId;
}
@override
int get hashCode => Object.hash(name, roleId, permissions);
}
class Permissions {
Permissions({
required this.home,
required this.crm,
required this.qr,
required this.orders,
required this.inventory,
required this.serviceOrder,
required this.support,
required this.sales,
required this.billing,
required this.technical,
required this.users,
required this.limited,
});
String? home;
String? crm;
String? qr;
String? orders;
String? inventory;
String? serviceOrder;
String? sales;
String? support;
String? billing;
String? users;
String? technical;
bool? limited;
factory Permissions.fromJson(String str) =>
Permissions.fromMap(json.decode(str));
factory Permissions.fromMap(Map<String, dynamic> json) => Permissions(
home: json['Home'],
crm: json['CRM'],
qr: json['QR'],
orders: json['Orders'],
inventory: json['Inventory'],
serviceOrder: json['Service Order'],
sales: json['Sales'],
support: json['Support'],
billing: json['Billing'],
users: json['Users'],
technical: json["Technical"],
limited: json["Limited"],
);
}

View File

@@ -0,0 +1,60 @@
import 'dart:convert';
import 'dart:developer';
import 'package:nethive_neo/helpers/globals.dart';
class Token {
Token({
required this.token,
required this.userId,
required this.email,
required this.created,
});
String token;
String userId;
String email;
DateTime created;
factory Token.fromJson(String str, String token) =>
Token.fromMap(json.decode(str), token);
String toJson() => json.encode(toMap());
factory Token.fromMap(Map<String, dynamic> payload, String token) {
return Token(
token: token,
userId: payload["user_id"],
email: payload["email"],
created: DateTime.parse(payload['created']),
);
}
Map<String, dynamic> toMap() => {
"user_id": userId,
"email": email,
"created": created,
};
Future<bool> validate(String type) async {
int timeLimit = 5;
try {
final minutesPassed =
DateTime.now().toUtc().difference(created).inMinutes;
if (minutesPassed < timeLimit) {
final res = await supabase
.from('token')
.select('token_$type')
.eq('user_id', userId);
final validatedToken = res[0]['token_$type'];
if (token == validatedToken) return true;
}
} catch (e) {
log('Error en validateToken - $e');
return false;
}
return false;
}
}

View File

@@ -0,0 +1,89 @@
import 'dart:convert';
import 'package:nethive_neo/models/users/role.dart';
class User {
User({
required this.id,
required this.sequentialId,
required this.firstName,
required this.lastName,
required this.email,
required this.role,
required this.mobilePhone,
required this.status,
this.image,
});
String id;
int sequentialId;
String firstName;
String lastName;
Role role;
String email;
String? mobilePhone;
String status;
String? image;
String get fullName => '$firstName $lastName';
int get statusColor {
late final int color;
switch (status) {
case 'Active':
color = 0XFF2EA437;
break;
default:
color = 0XFF2EA437;
}
return color;
}
bool get isAdmin => role.name == 'Administrator';
bool get isInventory => role.name == 'Inventory Warehouse';
bool get isSales => role.name == 'Sales Rep';
bool get isSupport => role.name == 'Support';
bool get isOperation => role.name == 'Operation';
factory User.fromJson(String str) => User.fromMap(json.decode(str));
factory User.fromMap(Map<String, dynamic> json) {
User user = User(
id: json["user_profile_id"],
sequentialId: json["sequential_id"],
firstName: json['first_name'],
lastName: json['last_name'],
role: Role.fromMap(json['role']),
email: json["email"],
mobilePhone: json['mobile_phone'],
status: json['status'],
image: json['image'],
);
return user;
}
User copyWith({
String? id,
int? sequentialId,
String? firstName,
String? lastName,
Role? role,
String? email,
String? mobilePhone,
String? status,
String? image,
}) {
return User(
id: id ?? this.id,
sequentialId: sequentialId ?? this.sequentialId,
firstName: firstName ?? this.firstName,
lastName: lastName ?? this.lastName,
role: role ?? this.role,
email: email ?? this.email,
mobilePhone: mobilePhone ?? this.mobilePhone,
status: status ?? this.status,
image: image ?? this.image,
);
}
}