bp - transfers - projected fields
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -613,6 +613,10 @@ export default class Authorizations {
return Authorizations.canPerformAction(loggedUser, Entity.INVOICE, Action.LIST);
}
+ public static async canListTransfers(loggedUser: UserToken): Promise<boolean> {
+ return Authorizations.canPerformAction(loggedUser, Entity.BILLING_TRANSFER, Action.LIST);
+ }
+
public static async canReadInvoiceBilling(loggedUser: UserToken, userID: string): Promise<boolean> {
return Authorizations.canPerformAction(loggedUser, Entity.INVOICE, Action.READ,
{ user: userID, owner: loggedUser.id });

MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -484,8 +484,11 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
]
},
{
- resource: Entity.BILLING_TRANSFER,
- action: [Action.LIST]
+ resource: Entity.BILLING_TRANSFER, action: [Action.LIST],
+ attributes: [
+ 'id', 'status', 'createdOn', 'sessions', 'amount', 'transferAmount', 'accountID', 'transferExternalID',
+ 'account.businessOwnerID', 'account.accountExternalID', 'businessOwner.name', 'businessOwner.firstName'
+ ]
},
{ resource: Entity.TAX, action: [Action.LIST] },
{

MODIFY
src/storage/mongodb/BillingStorage.ts
src/storage/mongodb/BillingStorage.ts
@@ -461,12 +461,25 @@ export default class BillingStorage {
aggregation.push({
$limit: dbParams.limit
});
+ // Add Sub-account
+ DatabaseUtils.pushAccountLookupInAggregation({
+ tenantID: tenant.id, aggregation: aggregation, asField: 'account', localField: 'accountID',
+ foreignField: '_id', oneToOneCardinality: true, oneToOneCardinalityNotNull: false
+ });
+ // Add Business Owner
+ DatabaseUtils.pushUserLookupInAggregation({
+ tenantID: tenant.id, aggregation: aggregation, asField: 'businessOwner', localField: 'account.businessOwnerID',
+ foreignField: '_id', oneToOneCardinality: true, oneToOneCardinalityNotNull: false
+ });
+ // Convert
+ DatabaseUtils.pushConvertObjectIDToString(aggregation, 'account.businessOwnerID');
// Add Last Changed / Created
DatabaseUtils.pushCreatedLastChangedInAggregation(tenant.id, aggregation);
// Handle the ID
DatabaseUtils.pushRenameDatabaseID(aggregation);
// Convert Object ID to string
DatabaseUtils.pushConvertObjectIDToString(aggregation, 'accountID');
+ DatabaseUtils.pushConvertObjectIDToString(aggregation, 'accountID');
// Project
DatabaseUtils.projectFields(aggregation, projectFields);
// Read DB

MODIFY
src/storage/mongodb/DatabaseUtils.ts
src/storage/mongodb/DatabaseUtils.ts
@@ -275,6 +275,13 @@ export default class DatabaseUtils {
}, additionalPipeline);
}
+ public static pushAccountLookupInAggregation(lookupParams: DbLookup, additionalPipeline: Record<string, any>[] = []): void {
+ DatabaseUtils.pushCollectionLookupInAggregation('billingsubaccounts', {
+ // objectIDFields: ['createdBy'],
+ ...lookupParams
+ }, additionalPipeline);
+ }
+
public static pushArrayFilterInAggregation(aggregation: any[], arrayName: string, filter: Record<string, any>): void {
// Unwind the array
aggregation.push({ '$unwind': { path: `$${arrayName}`, preserveNullAndEmptyArrays: true } });

bp - transfers - projected fields