Updates model

This commit is contained in:
thomashii@dukefirehawk.com 2021-05-03 21:49:19 +08:00
parent f27fe7381b
commit 2d6fdfbe8a

View file

@ -128,13 +128,13 @@ class RoleQuery extends Query<Role?, RoleQueryWhere?> {
@override @override
get(QueryExecutor executor) { get(QueryExecutor executor) {
return super.get(executor).then((result) { return super.get(executor).then((result) {
return result.fold<List<Role?>>([], (out, model) { return result.fold<List<Role>>([], (out, model) {
var idx = out.indexWhere((m) => m!.role == model!.role); var idx = out.indexWhere((m) => m.role == model!.role);
if (idx == -1) { if (idx == -1) {
return out..add(model); return out..add(model!);
} else { } else {
var l = out[idx]!; var l = out[idx];
return out return out
..[idx] = l.copyWith( ..[idx] = l.copyWith(
users: List<_User?>.from(l.users ?? []) users: List<_User?>.from(l.users ?? [])
@ -166,13 +166,13 @@ class RoleQuery extends Query<Role?, RoleQueryWhere?> {
@override @override
delete(QueryExecutor executor) { delete(QueryExecutor executor) {
return super.delete(executor).then((result) { return super.delete(executor).then((result) {
return result.fold<List<Role?>>([], (out, model) { return result.fold<List<Role>>([], (out, model) {
var idx = out.indexWhere((m) => m!.role == model!.role); var idx = out.indexWhere((m) => m.role == model!.role);
if (idx == -1) { if (idx == -1) {
return out..add(model); return out..add(model!);
} else { } else {
var l = out[idx]!; var l = out[idx];
return out return out
..[idx] = l.copyWith( ..[idx] = l.copyWith(
users: List<_User?>.from(l.users ?? []) users: List<_User?>.from(l.users ?? [])
@ -420,13 +420,13 @@ class UserQuery extends Query<User?, UserQueryWhere?> {
@override @override
update(QueryExecutor executor) { update(QueryExecutor executor) {
return super.update(executor).then((result) { return super.update(executor).then((result) {
return result.fold<List<User?>>([], (out, model) { return result.fold<List<User>>([], (out, model) {
var idx = out.indexWhere((m) => m!.email == model!.email); var idx = out.indexWhere((m) => m.email == model!.email);
if (idx == -1) { if (idx == -1) {
return out..add(model); return out..add(model!);
} else { } else {
var l = out[idx]!; var l = out[idx];
return out return out
..[idx] = l.copyWith( ..[idx] = l.copyWith(
roles: List<_Role?>.from(l.roles ?? []) roles: List<_Role?>.from(l.roles ?? [])
@ -439,13 +439,13 @@ class UserQuery extends Query<User?, UserQueryWhere?> {
@override @override
delete(QueryExecutor executor) { delete(QueryExecutor executor) {
return super.delete(executor).then((result) { return super.delete(executor).then((result) {
return result.fold<List<User?>>([], (out, model) { return result.fold<List<User>>([], (out, model) {
var idx = out.indexWhere((m) => m!.email == model!.email); var idx = out.indexWhere((m) => m.email == model!.email);
if (idx == -1) { if (idx == -1) {
return out..add(model); return out..add(model!);
} else { } else {
var l = out[idx]!; var l = out[idx];
return out return out
..[idx] = l.copyWith( ..[idx] = l.copyWith(
roles: List<_Role?>.from(l.roles ?? []) roles: List<_Role?>.from(l.roles ?? [])