-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcb268b
commit f761220
Showing
34 changed files
with
758 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/app/core/models/netsuite/db/destination-attribute.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { DestinationAttribute } from "../../db/destination-attribute.model"; | ||
|
||
type NetsuiteDestinationAttributeDetail = { | ||
country?: string; | ||
}; | ||
|
||
export interface NetsuiteDestinationAttribute extends DestinationAttribute { | ||
detail: NetsuiteDestinationAttributeDetail; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/app/core/models/netsuite/db/netsuite-credentials.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export type NetsuiteCredential = { | ||
id: number; | ||
ns_account_id: string; | ||
ns_consumer_key: string; | ||
ns_consumer_secret: string; | ||
ns_token_id: string; | ||
ns_token_secret: string; | ||
created_at: Date; | ||
updated_at: Date; | ||
workspace: number; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/app/core/models/netsuite/db/subsidiary-mapping.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { NetsuiteDestinationAttribute } from "./destination-attribute.model"; | ||
import { NetsuiteSubsidiaryMappingPost } from "../netsuite-configuration/netsuite-connector.model"; | ||
|
||
export type SubsidiaryMapping = { | ||
id?: number; | ||
subsidiary_name: string; | ||
country_name: string | null; | ||
internal_id: string; | ||
created_at?: Date; | ||
updated_at?: Date; | ||
workspace: number; | ||
}; | ||
|
||
|
||
export class NetsuiteSubsidiaryMappingModel { | ||
static constructPayload(netsuiteSubsidiaryId: any, subsidiaries: NetsuiteDestinationAttribute[], workspaceId: number): NetsuiteSubsidiaryMappingPost { | ||
const filteredSubsidiary = subsidiaries.filter(entity => entity.destination_id === netsuiteSubsidiaryId); | ||
return { | ||
subsidiary_name: filteredSubsidiary[0].value, | ||
internal_id: filteredSubsidiary[0].destination_id, | ||
country_name: filteredSubsidiary[0].detail?.country ? filteredSubsidiary[0].detail.country : null, | ||
workspace: workspaceId | ||
}; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/app/core/models/netsuite/netsuite-configuration/netsuite-connector.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { FormGroup } from "@angular/forms"; | ||
import { environment } from "src/environments/environment"; | ||
|
||
export type NetsuiteConnector = { | ||
ns_account_id: string; | ||
} | ||
|
||
export interface NetsuiteConnectorPost extends NetsuiteConnector { | ||
ns_token_id: string; | ||
ns_token_secret: string; | ||
} | ||
|
||
|
||
export class NetsuiteConnectorModel { | ||
static constructPayload(form: FormGroup): NetsuiteConnectorPost { | ||
return { | ||
ns_account_id: form.value.accountId, | ||
ns_token_id: form.value.tokenId, | ||
ns_token_secret: form.value.tokenSecret | ||
}; | ||
} | ||
} | ||
|
||
|
||
export type NetsuiteSubsidiaryMappingPost = { | ||
country_name: string | null, | ||
internal_id: string, | ||
subsidiary_name: string, | ||
workspace: number | ||
} |
79 changes: 79 additions & 0 deletions
79
src/app/core/models/netsuite/netsuite-configuration/netsuite-onboarding.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { brandingFeatureConfig } from "src/app/branding/branding-config"; | ||
import { NetsuiteOnboardingState } from "../../enum/enum.model"; | ||
import { OnboardingStepper } from "../../misc/onboarding-stepper.model"; | ||
|
||
|
||
type NetsuiteOnboardingStepperMap = { | ||
[NetsuiteOnboardingState.CONNECTION]: number, | ||
[NetsuiteOnboardingState.SUBSIDIARY]: number, | ||
[NetsuiteOnboardingState.EXPORT_SETTINGS]: number, | ||
[NetsuiteOnboardingState.IMPORT_SETTINGS]: number, | ||
[NetsuiteOnboardingState.ADVANCED_CONFIGURATION]: number, | ||
[NetsuiteOnboardingState.COMPLETE]: number, | ||
} | ||
|
||
export class NetsuiteOnboardingModel { | ||
private onboardingSteps: OnboardingStepper[] = [ | ||
{ | ||
active: false, | ||
completed: false, | ||
step: 'Connect to NetSuite', | ||
icon: 'link-vertical-medium', | ||
route: '/integrations/netsuite/onboarding/connector', | ||
styleClasses: ['step-name-connector--text'] | ||
}, | ||
{ | ||
active: false, | ||
completed: false, | ||
step: 'Export Settings', | ||
icon: 'arrow-tail-up-medium', | ||
route: '/integrations/netsuite/onboarding/export_settings', | ||
styleClasses: ['step-name-export--text'] | ||
}, | ||
{ | ||
active: false, | ||
completed: false, | ||
step: 'Import Settings', | ||
icon: 'arrow-tail-down-medium', | ||
route: '/integrations/netsuite/onboarding/import_settings', | ||
styleClasses: ['step-name-export--text'] | ||
}, | ||
{ | ||
active: false, | ||
completed: false, | ||
step: 'Advanced Settings', | ||
icon: 'gear-medium', | ||
route: '/integrations/netsuite/onboarding/advanced_settings', | ||
styleClasses: ['step-name-advanced--text'] | ||
} | ||
]; | ||
|
||
private readonly onboardingStateStepMap: NetsuiteOnboardingStepperMap = { | ||
[NetsuiteOnboardingState.CONNECTION]: 1, | ||
[NetsuiteOnboardingState.SUBSIDIARY]: 2, | ||
[NetsuiteOnboardingState.EXPORT_SETTINGS]: 3, | ||
[NetsuiteOnboardingState.IMPORT_SETTINGS]: 4, | ||
[NetsuiteOnboardingState.ADVANCED_CONFIGURATION]: 5, | ||
[NetsuiteOnboardingState.COMPLETE]: 6 | ||
}; | ||
|
||
getOnboardingSteps(currentStep: string, onboardingState: NetsuiteOnboardingState): OnboardingStepper[] { | ||
this.onboardingSteps.forEach(step => { | ||
if (step.step.toLowerCase() === currentStep.toLowerCase()) { | ||
step.active = true; | ||
} else { | ||
step.active = false; | ||
} | ||
}); | ||
|
||
for (let index = this.onboardingStateStepMap[onboardingState] - 2; index > 0; index--) { | ||
this.onboardingSteps[index - 1].completed = true; | ||
} | ||
|
||
if (!brandingFeatureConfig.featureFlags.mapEmployees) { | ||
this.onboardingSteps.splice(1, 1); | ||
} | ||
|
||
return this.onboardingSteps; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/app/core/services/netsuite/netsuite-core/netsuite-connector.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { NetsuiteConnectorService } from './netsuite-connector.service'; | ||
|
||
describe('NetsuiteConnectorService', () => { | ||
let service: NetsuiteConnectorService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(NetsuiteConnectorService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
57 changes: 57 additions & 0 deletions
57
src/app/core/services/netsuite/netsuite-core/netsuite-connector.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { CacheBuster, Cacheable, globalCacheBusterNotifier } from 'ts-cacheable'; | ||
import { ApiService } from '../../common/api.service'; | ||
import { StorageService } from '../../common/storage.service'; | ||
import { NetsuiteCredential } from 'src/app/core/models/netsuite/db/netsuite-credentials.model'; | ||
import { SubsidiaryMapping } from 'src/app/core/models/netsuite/db/subsidiary-mapping.model'; | ||
import { Observable, Subject } from 'rxjs'; | ||
import { NetsuiteConnectorPost, NetsuiteSubsidiaryMappingPost } from 'src/app/core/models/netsuite/netsuite-configuration/netsuite-connector.model'; | ||
import { WorkspaceService } from '../../common/workspace.service'; | ||
|
||
|
||
const netsuiteCredentialCache = new Subject<void>(); | ||
|
||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class NetsuiteConnectorService { | ||
|
||
workspaceId: number; | ||
|
||
constructor( | ||
private apiService: ApiService, | ||
private workspaceService: WorkspaceService, | ||
private storageService: StorageService | ||
) { } | ||
|
||
@Cacheable({ | ||
cacheBusterObserver: netsuiteCredentialCache | ||
}) | ||
getNetsuiteCredentials(): Observable<NetsuiteCredential> { | ||
this.workspaceId = this.storageService.get('workspaceId'); | ||
return this.apiService.get(`/workspaces/${this.workspaceId}/credentials/netsuite/`, {}); | ||
} | ||
|
||
@CacheBuster({ | ||
cacheBusterNotifier: netsuiteCredentialCache | ||
}) | ||
connectNetsuite(data: NetsuiteConnectorPost): Observable<NetsuiteCredential> { | ||
this.workspaceId = this.storageService.get('workspaceId'); | ||
globalCacheBusterNotifier.next(); | ||
return this.apiService.post(`/workspaces/${this.workspaceId}/credentials/netsuite/`, data); | ||
} | ||
|
||
postSubsdiaryMapping(subsdiaryMappingPayload: NetsuiteSubsidiaryMappingPost): Observable<SubsidiaryMapping> { | ||
const workspaceId = this.workspaceService.getWorkspaceId(); | ||
|
||
return this.apiService.post(`/workspaces/${workspaceId}/mappings/subsidiaries/`, subsdiaryMappingPayload); | ||
} | ||
|
||
getSubsidiaryMapping(): Observable<SubsidiaryMapping> { | ||
const workspaceId = this.workspaceService.getWorkspaceId(); | ||
return this.apiService.get( | ||
`/workspaces/${workspaceId}/mappings/subsidiaries/`, {} | ||
); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/app/core/services/netsuite/netsuite-core/netsuite-mappings.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { NetsuiteMappingsService } from './netsuite-mappings.service'; | ||
|
||
describe('NetsuiteMappingsService', () => { | ||
let service: NetsuiteMappingsService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(NetsuiteMappingsService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
src/app/core/services/netsuite/netsuite-core/netsuite-mappings.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ApiService } from '../../common/api.service'; | ||
import { Observable } from 'rxjs'; | ||
import { WorkspaceService } from '../../common/workspace.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class NetsuiteMappingsService { | ||
|
||
constructor( | ||
private apiService: ApiService, | ||
private workspaceService: WorkspaceService | ||
) { } | ||
|
||
refreshNetsuiteDimensions(dimensionsToSync: string[] = []) { | ||
const workspaceId = this.workspaceService.getWorkspaceId(); | ||
|
||
return this.apiService.post(`/workspaces/${workspaceId}/netsuite/refresh_dimensions/`, { | ||
dimensions_to_sync: dimensionsToSync | ||
}); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/app/core/services/netsuite/netsuite-core/netsuite-workspace.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { NetsuiteWorkspaceService } from './netsuite-workspace.service'; | ||
|
||
describe('NetsuiteWorkspaceService', () => { | ||
let service: NetsuiteWorkspaceService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(NetsuiteWorkspaceService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.