Skip to content

Commit

Permalink
towards MVP
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmungai committed Dec 22, 2020
1 parent 297f35c commit c3e64b2
Show file tree
Hide file tree
Showing 28 changed files with 524 additions and 327 deletions.
6 changes: 1 addition & 5 deletions firebase/firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:kekea_core/utils/debug_print.dart';
import 'package:meta/meta.dart';
import 'package:bloc/bloc.dart';
import './bloc.dart';
Expand Down Expand Up @@ -30,6 +31,7 @@ class BusinessPersonBloc
businessPersonDBFirestore.updateBusinessPerson(
businessPerson: businessPerson,
);
dPrint("updatedBusinessPerson: $updatedBusinessPerson");
yield BusinessPersonState.updateSuccess(
businessPerson: updatedBusinessPerson,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:kekea_core/side_effects/database/firestore/business_member_db_firestore.dart';
import 'package:kekea_core/side_effects/dynamic_link/dynamic_link.dart';
import 'package:kekea_core/utils/debug_print.dart';
import 'package:meta/meta.dart';
import 'package:built_collection/built_collection.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
Expand Down Expand Up @@ -48,6 +50,7 @@ class BusinessPersonStatusBloc
final PaymentBloc paymentBloc;
final PaymentProductDBFirestore paymentProductDBFirestore;
final ProductDBFirestore productDBFirestore;
final BusinessMemberDBFirestore businessMemberDBFirestore;
final DynamicLink dynamicLink;

final StoreDBFirestore storeDBFirestore;
Expand All @@ -66,6 +69,7 @@ class BusinessPersonStatusBloc
@required this.paymentProductDBFirestore,
@required this.productDBFirestore,
@required this.dynamicLink,
@required this.businessMemberDBFirestore,
}) : assert(businessPersonDBFirestore != null &&
businessPersonBloc != null &&
businessMemberBloc != null &&
Expand All @@ -76,7 +80,8 @@ class BusinessPersonStatusBloc
paymentBloc != null &&
paymentProductDBFirestore != null &&
productDBFirestore != null &&
dynamicLink != null),
dynamicLink != null &&
businessMemberDBFirestore != null),
super(BusinessPersonStatusState.absent());

@override
Expand Down Expand Up @@ -115,101 +120,52 @@ class BusinessPersonStatusBloc
yield BusinessPersonStatusState.present(
businessPerson: businessPerson,
);
final _defaultBusiness = businessPerson?.defaultBusiness?.id;
if (_defaultBusiness == null) {
final Business defaultBusiness =
businessDBFirestore.createBusinessDocument(business: Business());
final String _defaultBusiness = businessPerson?.defaultBusiness?.id;
final String _defaultStore = businessPerson?.defaultStore?.id;

add(
BusinessPersonStatusEvent.setDefaultBusiness(
defaultBusiness: defaultBusiness,
),
if (_defaultBusiness == null && _defaultStore == null) {
final Business business = businessDBFirestore.createBusinessDocument(
business: Business(),
);

final Store store = storeDBFirestore.createStore(
businessId: business.id,
store: Store(),
);

add(
BusinessPersonStatusEvent.createBusinessMember(
businessId: defaultBusiness.id,
final BusinessPerson updatedBusinessPerson =
businessPersonDBFirestore.updateBusinessPerson(
businessPerson: businessPerson.copyWith(
defaultBusiness: business,
defaultStore: store,
),
);
final _defaultStore = businessPerson?.defaultStore?.id;
if (_defaultStore == null) {
final Store store = storeDBFirestore.createStore(
businessId: defaultBusiness.id,
store: Store(),
);

add(
BusinessPersonStatusEvent.setDefaultStore(
store: store,
businessId: defaultBusiness.id,
),
);
}
yield BusinessPersonStatusState.present(
businessPerson: updatedBusinessPerson,
);

final BusinessMember businessMember =
businessMemberDBFirestore.createBusinessMember(
businessId: business.id,
businessMember: BusinessMember(
firebaseId: businessPerson.firebaseId,
),
);
}
},
setAbsent: (String firebaseId) async* {
yield BusinessPersonStatusState.absent();
businessPersonBloc.add(
bpc.BusinessPersonEvent.createBusinessPerson(
businessPerson: BusinessPerson(
firebaseId: firebaseId,
),
final bizPerson = businessPersonDBFirestore.createBusinessPerson(
businessPerson: BusinessPerson(
firebaseId: firebaseId,
),
);
},
stopListening: () async* {
_streamSubscription?.cancel();
yield BusinessPersonStatusState.absent();
},
setDefaultBusiness: (Business defaultBusiness) async* {
yield* state.maybeWhen(
present: (BusinessPerson businessPerson) async* {
businessPersonBloc.add(
bpc.BusinessPersonEvent.updateBusinessPerson(
businessPerson: businessPerson.copyWith(
defaultBusiness: defaultBusiness,
),
),
);
},
orElse: () async* {
yield state;
},
);
},
createBusinessMember: (String businessId) async* {
yield* state.maybeWhen(
present: (BusinessPerson businessPerson) async* {
businessMemberBloc.add(
BusinessMemberEvent.create(
businessId: businessId,
businessMember: BusinessMember(
firebaseId: businessPerson.firebaseId,
),
),
);
},
orElse: () async* {
yield state;
},
);
},
setDefaultStore: (Store store, String businessId) async* {
yield* state.maybeWhen(
present: (BusinessPerson businessPerson) async* {
businessPersonBloc.add(
bpc.BusinessPersonEvent.updateBusinessPerson(
businessPerson: businessPerson.copyWith(
defaultStore: store,
),
),
);
},
orElse: () async* {
yield state;
},
);
},
submitPayment: (
PaymentMethod paymentMethod,
Customer customer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ abstract class BusinessPersonStatusEvent with _$BusinessPersonStatusEvent {
@required String firebaseId,
}) = _SetAbsent;
const factory BusinessPersonStatusEvent.stopListening() = _StopListening;
const factory BusinessPersonStatusEvent.setDefaultBusiness({
@required Business defaultBusiness,
}) = _SetDefaultBusiness;
const factory BusinessPersonStatusEvent.createBusinessMember({
@required String businessId,
}) = _CreateBusinessMember;
const factory BusinessPersonStatusEvent.setDefaultStore({
@required Store store,
@required String businessId,
}) = _CreateStore;
const factory BusinessPersonStatusEvent.submitPayment({
@required PaymentMethod paymentMethod,
@required Customer customer,
Expand Down
20 changes: 14 additions & 6 deletions kekea_core/lib/data/business/business.g.dart

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

26 changes: 17 additions & 9 deletions kekea_core/lib/data/business_member/business_member.g.dart

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

39 changes: 26 additions & 13 deletions kekea_core/lib/data/business_person/business_person.g.dart

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

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

20 changes: 14 additions & 6 deletions kekea_core/lib/data/currency/currency.g.dart

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

Loading

0 comments on commit c3e64b2

Please sign in to comment.