@cfxlabsinc/b2b-services
    Preparing search index...

    Resolves a recipient to the reward account that holds its balance, and moves a pending account onto an entity's account when the entity is approved.

    Index
    instance: (...args: []) => RewardAccountService = ...

    The process default: built from each dependency's own instance().

    • Locks and returns the account rewards for id now land on: itself, or where it was promoted to. Waits on id's lock, which a running promotion holds, then follows a promotion it committed.

      Parameters

      • __namedParameters: { customerId: string; id: number }
      • tx: PgAsyncTransaction

      Returns Promise<
          {
              account: {
                  createdAt: Date;
                  customerExternalId: string;
                  customerId: number;
                  externalId: string;
                  id: number;
                  identityExternalId: string
                  | null;
                  identityId: number | null;
                  organizationExternalId: string | null;
                  organizationId: number | null;
                  promotedAt: Date | null;
                  promotedToId: number | null;
                  recipient: string | null;
                  recipientType: "EMAIL" | "PHONE" | null;
                  updatedAt: Date;
              };
              legacyKey: string;
          },
      >

    • The account a recipient resolves to, without creating one: null when it has none yet. For reads, so probing an email or phone writes nothing.

      Parameters

      • __namedParameters: ({ entityId: string } | { email: string } | { phone: string }) & {
            customerId: string;
        }

      Returns Promise<
          | { error: RewardAccountError; ok: false }
          | {
              ok: true;
              value:
                  | {
                      createdAt: Date;
                      customerExternalId: string;
                      customerId: number;
                      externalId: string;
                      id: number;
                      identityExternalId: string
                      | null;
                      identityId: number | null;
                      organizationExternalId: string | null;
                      organizationId: number | null;
                      promotedAt: Date | null;
                      promotedToId: number | null;
                      recipient: string | null;
                      recipientType: "EMAIL" | "PHONE" | null;
                      updatedAt: Date;
                  }
                  | null;
          },
      >

    • Moves every pending account addressed to the entity's email or phone onto the entity's own account, once the entity is approved. Each pending account's ledger rows are repointed and the account is stamped promoted, in one transaction, so a retry finds nothing left to move.

      Parameters

      • __namedParameters: { customerId: string; entityId: string }

      Returns Promise<
          | { error: RewardAccountError; ok: false }
          | { ok: true; value: { promotedAccountIds: string[] } },
      >

      the ids of the pending accounts that were promoted

    • The account a recipient's rewards land on, created on first use. A phone or email already held by a live identity resolves to that identity's account, so a promo sent to a member is not left pending.

      approved is whether the owning entity may transact; false for a pending account. Debits and claims require it.

      Parameters

      • __namedParameters: RewardRecipient & { customerId: string }
      • Optionaltx: PgAsyncTransaction<NodePgQueryResultHKT, EmptyRelations>

      Returns Promise<
          | {
              ok: true;
              value: {
                  account: {
                      createdAt: Date;
                      customerExternalId: string;
                      customerId: number;
                      externalId: string;
                      id: number;
                      identityExternalId: string
                      | null;
                      identityId: number | null;
                      organizationExternalId: string | null;
                      organizationId: number | null;
                      promotedAt: Date | null;
                      promotedToId: number | null;
                      recipient: string | null;
                      recipientType: "EMAIL" | "PHONE" | null;
                      updatedAt: Date;
                  };
                  approved: boolean;
              };
          }
          | { error: RewardAccountError; ok: false },
      >