Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(recipients-app): Remove redundant update by and at fields from recipient and payment #648

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,13 @@ class SocialIncomePayment extends Equatable {
final PaymentStatus? status;
final String? comments;

@JsonKey(name: "last_updated_by")
final String? updatedBy;

@JsonKey(name: "last_updated_at")
final Timestamp? updatedAt;

const SocialIncomePayment({
required this.id,
this.amount,
this.paymentAt,
this.currency,
this.status,
this.comments,
this.updatedBy,
this.updatedAt,
});

factory SocialIncomePayment.fromJson(Map<String, dynamic> json) =>
Expand All @@ -49,8 +41,6 @@ class SocialIncomePayment extends Equatable {
currency,
status,
comments,
updatedBy,
updatedAt,
];
}

Expand All @@ -61,8 +51,6 @@ class SocialIncomePayment extends Equatable {
String? comments,
String? currency,
PaymentStatus? status,
String? updatedBy,
Timestamp? updatedAt,
}) {
return SocialIncomePayment(
id: id ?? this.id,
Expand All @@ -71,8 +59,6 @@ class SocialIncomePayment extends Equatable {
comments: comments ?? this.comments,
currency: currency ?? this.currency,
status: status ?? this.status,
updatedBy: updatedBy ?? this.updatedBy,
updatedAt: updatedAt ?? this.updatedAt,
);
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions recipients_app/lib/data/models/recipient.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ class Recipient extends Equatable {
@JsonKey(name: "next_survey")
final Timestamp? nextSurvey;

@JsonKey(name: "last_updated_by")
final String? updatedBy;

// this should be got from `/recipients/<recipient.id>/payments` collection
@JsonKey(includeFromJson: false, includeToJson: false)
final List<SocialIncomePayment>? payments;
Expand All @@ -100,7 +97,6 @@ class Recipient extends Equatable {
this.nextSurvey,
this.organizationRef,
this.payments = const [],
this.updatedBy,
});

@override
Expand All @@ -126,7 +122,6 @@ class Recipient extends Equatable {
nextSurvey,
organizationRef,
payments,
updatedBy,
];
}

Expand All @@ -151,7 +146,6 @@ class Recipient extends Equatable {
Timestamp? nextSurvey,
DocumentReference? organizationRef,
List<SocialIncomePayment>? payments,
String? updatedBy,
}) {
return Recipient(
userId: userId ?? this.userId,
Expand All @@ -175,7 +169,6 @@ class Recipient extends Equatable {
nextSurvey: nextSurvey ?? this.nextSurvey,
organizationRef: organizationRef ?? this.organizationRef,
payments: payments ?? this.payments,
updatedBy: updatedBy ?? this.updatedBy,
);
}

Expand Down
2 changes: 0 additions & 2 deletions recipients_app/lib/data/models/recipient.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import "package:app/data/repositories/repositories.dart";
import "package:cloud_firestore/cloud_firestore.dart";

const String paymentCollection = "payments";
const String kUpdatedByAppUser = "app user";

class PaymentRepository {
final FirebaseFirestore firestore;
Expand Down Expand Up @@ -37,16 +36,12 @@ class PaymentRepository {
}

/// This updates the payment status to confirmed
/// and also sets lastUpdatedAt and lastUpdatedBy to the
/// current time and recipient
Future<void> confirmPayment({
required Recipient recipient,
required SocialIncomePayment payment,
}) async {
final updatedPayment = payment.copyWith(
status: PaymentStatus.confirmed,
updatedBy: "${recipient.userId}",
updatedAt: Timestamp.now(),
);

await firestore
Expand All @@ -65,8 +60,6 @@ class PaymentRepository {
final updatedPayment = payment.copyWith(
status: PaymentStatus.contested,
comments: contestReason,
updatedBy: "${recipient.userId}",
updatedAt: Timestamp.now(),
);

await firestore
Expand Down
4 changes: 1 addition & 3 deletions recipients_app/lib/data/repositories/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ class UserRepository {
firebaseAuth.signInWithCredential(credentials);

Future<void> updateRecipient(Recipient recipient) async {
final updatedRecipient = recipient.copyWith(updatedBy: kUpdatedByAppUser);

return firestore
.collection(recipientCollection)
.doc(recipient.userId)
.update(updatedRecipient.toJson());
.update(recipient.toJson());
}
}
Loading