acceptMembership static method

Future<MemberModel> acceptMembership(
  1. MemberModel member,
  2. AppModel app
)

Implementation

static Future<MemberModel> acceptMembership(
    MemberModel member, AppModel app) async {
  if (isSubscibred(member, app)) return member;

  var subscriptions = member.subscriptions!;
  subscriptions
      .add(MemberSubscriptionModel(documentID: newRandomKey(), app: app));
  member = member.copyWith(subscriptions: subscriptions);
  var returnMe = await memberRepository()!.update(member);

  var accessModel =
      await accessRepository(appId: app.documentID)!.get(member.documentID);
  if (accessModel == null) {
    // create an access entry. creation with privilege level 0 is allowed
    await accessRepository(appId: app.documentID)!.add(AccessModel(
      documentID: member.documentID,
      appId: app.documentID,
      privilegeLevel: PrivilegeLevel.noPrivilege,
      points: 0,
    ));
  }

  return returnMe;
}