Skip to content

Commit

Permalink
refactor: Augment organization types in organization lib (#8499) (#9280)
Browse files Browse the repository at this point in the history
  • Loading branch information
marlass committed Oct 30, 2020
1 parent 6885dde commit a181a2d
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InjectionToken } from '@angular/core';
import { Converter, EntitiesModel } from '@spartacus/core';
import { UserGroup } from '../../model';
import { UserGroup } from '../../model/user-group.model';

export const USER_GROUP_NORMALIZER = new InjectionToken<
Converter<any, UserGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Currency, B2BApprovalProcess } from '@spartacus/core';

declare module '@spartacus/core' {
interface B2BUnit {
parentOrgUnit?: Partial<B2BUnit>;
approvalProcess?: B2BApprovalProcess;
administrators?: B2BUser[];
approvers?: B2BUser[];
customers?: B2BUser[];
costCenters?: CostCenter[];
managers?: B2BUser[];
}

interface B2BUser {
approvers?: [];
orgUnit?: B2BUnit;
selected?: boolean;
isAssignedToApprovers?: boolean;
email?: string;
}

interface CostCenter {
activeFlag?: boolean;
currency?: Currency;
originalCode?: string;
}
}
2 changes: 2 additions & 0 deletions feature-libs/organization/administration/core/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export * from './organization-item-status';
export * from './permission.model';
export * from './unit-node.model';
export * from './user-group.model';
// Imported for side effects (module augmentation)
import './augmented-core.model';
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
B2BUser,
CostCenter,
ListModel,
StateUtils,
OrderApprovalPermissionType,
StateUtils,
} from '@spartacus/core';
import { Budget } from '../model/budget.model';
import { Permission } from '../model/permission.model';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
B2BUser,
CostCenter,
ListModel,
StateUtils,
OrderApprovalPermissionType,
StateUtils,
} from '@spartacus/core';
import { Budget } from '../../model/budget.model';
import { Permission } from '../../model/permission.model';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { OrderApprovalPermissionResult } from './order-approval.model';

declare module '@spartacus/core' {
interface Order {
permissionResults?: OrderApprovalPermissionResult[];
}
}
2 changes: 2 additions & 0 deletions feature-libs/organization/order-approval/core/model/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './order-approval.model';
// Imported for side effects (module augmentation)
import './augmented-core.model';
2 changes: 2 additions & 0 deletions projects/core/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ export * from './src/lazy-loading/index';
export { Product } from './src/model/product.model';
export { ProductSearchPage, Facet } from './src/model/product-search.model';
export { Cart } from './src/model/cart.model';
export { CostCenter, B2BUnit, B2BUser } from './src/model/org-unit.model';
export { AuthToken } from './src/auth/user-auth/models/auth-token.model';
export { Order } from './src/model/order.model';
/** AUGMENTABLE_TYPES_END */
1 change: 0 additions & 1 deletion projects/core/src/model/order.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ export interface Order {
orderDiscounts?: Price;
orgCustomer?: B2BUser;
paymentInfo?: PaymentDetails;
permissionResults?: any[]; //OrderApprovalPermissionResult[];
pickupItemsQuantity?: number;
pickupOrderGroups?: PickupOrderEntryGroup[];
productDiscounts?: Price;
Expand Down
18 changes: 1 addition & 17 deletions projects/core/src/model/org-unit.model.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { Address } from './address.model';
import { Currency, User } from './misc.model';
import { User } from './misc.model';

// TODO(#8876): Should we simplify the models only for the fields required by the B2B checkout?
export interface CostCenter {
active?: boolean;
activeFlag?: boolean;
code?: string;
name?: string;
originalCode?: string;
unit?: B2BUnit;
currency?: Currency;
}

export enum B2BUserGroup {
Expand All @@ -24,23 +21,10 @@ export interface B2BUnit {
addresses?: Address[];
uid?: string;
name?: string;
parentOrgUnit?: Partial<B2BUnit>;
approvalProcess?: B2BApprovalProcess;
administrators?: B2BUser[];
approvers?: B2BUser[];
customers?: B2BUser[];
costCenters?: CostCenter[];
managers?: B2BUser[];
}

export interface B2BUser extends User {
active?: boolean;
approvers?: [];
orgUnit?: B2BUnit;
roles?: string[];
selected?: boolean;
isAssignedToApprovers?: boolean;
email?: string;
}

export interface B2BApprovalProcess {
Expand Down

0 comments on commit a181a2d

Please sign in to comment.