Add pricing entry flow and platform admin foundations
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
import '../api/pocketbase_client.dart';
|
||||
import '../../models/platform_admin.dart';
|
||||
import '../../models/tenant.dart';
|
||||
import '../../models/user_profile.dart';
|
||||
|
||||
@@ -73,10 +74,24 @@ class AuthRepository {
|
||||
String id, {
|
||||
String? companyName,
|
||||
String? defaultCurrency,
|
||||
String? companyAddress,
|
||||
String? city,
|
||||
String? district,
|
||||
double? latitude,
|
||||
double? longitude,
|
||||
List<String>? workflowOverrides,
|
||||
}) async {
|
||||
final body = <String, dynamic>{};
|
||||
if (companyName != null) body['company_name'] = companyName;
|
||||
if (defaultCurrency != null) body['default_currency'] = defaultCurrency;
|
||||
if (companyAddress != null) body['company_address'] = companyAddress;
|
||||
if (city != null) body['city'] = city;
|
||||
if (district != null) body['district'] = district;
|
||||
if (latitude != null) body['latitude'] = latitude;
|
||||
if (longitude != null) body['longitude'] = longitude;
|
||||
if (workflowOverrides != null) {
|
||||
body['workflow_overrides'] = workflowOverrides;
|
||||
}
|
||||
if (body.isEmpty) return;
|
||||
await _pb.collection('tenants').update(id, body: body);
|
||||
}
|
||||
@@ -85,26 +100,51 @@ class AuthRepository {
|
||||
final record = _pb.authStore.record!;
|
||||
final user = UserProfile.fromJson(record.toJson());
|
||||
List<TenantMembership> tenants = [];
|
||||
List<PlatformMembership> platformMemberships = [];
|
||||
try {
|
||||
tenants = await _fetchUserTenants(record.id);
|
||||
} catch (_) {}
|
||||
return AuthResult(user: user, tenants: tenants);
|
||||
try {
|
||||
platformMemberships = await _fetchPlatformMemberships(record.id);
|
||||
} catch (_) {}
|
||||
return AuthResult(
|
||||
user: user,
|
||||
tenants: tenants,
|
||||
platformMemberships: platformMemberships,
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<TenantMembership>> _fetchUserTenants(String userId) async {
|
||||
final result = await _pb.collection('tenant_members').getList(
|
||||
filter: 'user_id = "$userId"',
|
||||
expand: 'tenant_id',
|
||||
perPage: 50,
|
||||
);
|
||||
filter: 'user_id = "$userId"',
|
||||
expand: 'tenant_id',
|
||||
perPage: 50,
|
||||
);
|
||||
return result.items
|
||||
.map((r) => TenantMembership.fromJson(r.toJson()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<List<PlatformMembership>> _fetchPlatformMemberships(
|
||||
String userId,
|
||||
) async {
|
||||
final result = await _pb.collection('platform_memberships').getList(
|
||||
filter: 'user_id = "$userId"',
|
||||
perPage: 20,
|
||||
);
|
||||
return result.items
|
||||
.map((r) => PlatformMembership.fromJson(r.toJson()))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
class AuthResult {
|
||||
const AuthResult({required this.user, required this.tenants});
|
||||
const AuthResult({
|
||||
required this.user,
|
||||
required this.tenants,
|
||||
this.platformMemberships = const [],
|
||||
});
|
||||
final UserProfile user;
|
||||
final List<TenantMembership> tenants;
|
||||
final List<PlatformMembership> platformMemberships;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user