blah
This commit is contained in:
@@ -7,7 +7,7 @@ class ApiService {
|
||||
|
||||
ApiService(this.pb);
|
||||
|
||||
String? get userId => pb.authStore.model?.id;
|
||||
String? get userId => pb.authStore.record?.id;
|
||||
|
||||
Future<void> login(String email, String password) async {
|
||||
await pb.collection('users').authWithPassword(email, password);
|
||||
@@ -21,6 +21,7 @@ class ApiService {
|
||||
'email': email,
|
||||
'password': password,
|
||||
'passwordConfirm': password,
|
||||
'emailVisibility': true,
|
||||
},
|
||||
);
|
||||
await login(email, password);
|
||||
@@ -46,6 +47,26 @@ class ApiService {
|
||||
return Liste.fromJson(rec.toJson());
|
||||
}
|
||||
|
||||
Future<void> updateList(
|
||||
String listId, {
|
||||
String? title,
|
||||
List<String>? members,
|
||||
}) async {
|
||||
if (title == null && members == null) return;
|
||||
final body = <String, dynamic>{};
|
||||
if (title != null) {
|
||||
body['title'] = title;
|
||||
}
|
||||
if (members != null) {
|
||||
body['members'] = members;
|
||||
}
|
||||
await pb.collection('lists').update(listId, body: body);
|
||||
}
|
||||
|
||||
Future<void> deleteList(String listId) async {
|
||||
await pb.collection('lists').delete(listId);
|
||||
}
|
||||
|
||||
Future<List<Item>> getItems(String listId) async {
|
||||
final List<RecordModel> res = await pb
|
||||
.collection('items')
|
||||
@@ -67,8 +88,33 @@ class ApiService {
|
||||
return Item.fromJson(rec.toJson());
|
||||
}
|
||||
|
||||
Future<void> updateItem(String itemId, {bool? checked}) async {
|
||||
if (checked == null) return;
|
||||
await pb.collection('items').update(itemId, body: {'checked': checked});
|
||||
Future<void> deleteItem(String itemId) async {
|
||||
await pb.collection('items').delete(itemId);
|
||||
}
|
||||
|
||||
Future<void> updateItem(String itemId, {bool? checked, String? name}) async {
|
||||
if (checked == null && name == null) return;
|
||||
final Map<String, dynamic> body = <String, dynamic>{};
|
||||
if (checked != null) {
|
||||
body['checked'] = checked;
|
||||
}
|
||||
if (name != null) {
|
||||
body['name'] = name;
|
||||
}
|
||||
await pb.collection('items').update(itemId, body: body);
|
||||
}
|
||||
|
||||
Future<RecordModel?> findUserByEmail(String email) async {
|
||||
try {
|
||||
return await pb.collection('users').getFirstListItem('email = "$email"');
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<RecordModel>> getUsersByIds(List<String> ids) async {
|
||||
if (ids.isEmpty) return [];
|
||||
final String filter = ids.map((id) => 'id = "$id"').join(' || ');
|
||||
return await pb.collection('users').getFullList(filter: filter);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user