-
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.
Showing
111 changed files
with
1,929 additions
and
14 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
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,15 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { TenantGuard } from './tenant.guard'; | ||
|
||
describe('WorkspacesGuard', () => { | ||
let guard: TenantGuard; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
guard = TestBed.inject(TenantGuard); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(guard).toBeTruthy(); | ||
}); | ||
}); |
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,49 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router'; | ||
import { forkJoin, Observable, throwError } from 'rxjs'; | ||
import { map, catchError } from 'rxjs/operators'; | ||
import { globalCacheBusterNotifier } from 'ts-cacheable'; | ||
import { ToastSeverity, XeroOnboardingState } from '../models/enum/enum.model'; | ||
import { XeroConnectorService } from '../services/xero/xero-configuration/xero-connector.service'; | ||
import { WorkspaceService } from '../services/common/workspace.service'; | ||
import { IntegrationsToastService } from '../services/common/integrations-toast.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class TenantGuard implements CanActivate { | ||
|
||
constructor( | ||
private xeroConnectorService: XeroConnectorService, | ||
private router: Router, | ||
private workspaceService: WorkspaceService, | ||
private toastService: IntegrationsToastService | ||
) { } | ||
|
||
canActivate( | ||
route: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { | ||
const workspaceId = this.workspaceService.getWorkspaceId(); | ||
|
||
if (!workspaceId) { | ||
return this.router.navigateByUrl(`workspaces`); | ||
} | ||
|
||
return forkJoin( | ||
[ | ||
this.xeroConnectorService.getTenantMappings() | ||
] | ||
).pipe( | ||
map(response => !!response), | ||
catchError(error => { | ||
if (error.status === 400) { | ||
globalCacheBusterNotifier.next(); | ||
this.toastService.displayToastMessage(ToastSeverity.ERROR, 'Oops! You will need to select a tenant to proceed with the onboarding.'); | ||
return this.router.navigateByUrl('integrations/xero/onboarding/xero_connector'); | ||
} | ||
return throwError(error); | ||
}) | ||
); | ||
} | ||
|
||
} |
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 { XeroTokenGuard } from './xero-token.guard'; | ||
|
||
describe('XeroTokenGuard', () => { | ||
let guard: XeroTokenGuard; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
guard = TestBed.inject(XeroTokenGuard); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(guard).toBeTruthy(); | ||
}); | ||
}); |
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,55 @@ | ||
import { Injectable } from "@angular/core"; | ||
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from "@angular/router"; | ||
import { XeroConnectorService } from "../services/xero/xero-configuration/xero-connector.service"; | ||
import { Observable, forkJoin, map, catchError, throwError } from "rxjs"; | ||
import { globalCacheBusterNotifier } from "ts-cacheable"; | ||
import { WorkspaceService } from "../services/common/workspace.service"; | ||
import { ToastSeverity, XeroOnboardingState } from "../models/enum/enum.model"; | ||
import { IntegrationsToastService } from "../services/common/integrations-toast.service"; | ||
|
||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class XeroTokenGuard implements CanActivate { | ||
|
||
constructor( | ||
private xeroConnectorService: XeroConnectorService, | ||
private router: Router, | ||
private toastService: IntegrationsToastService, | ||
private workspaceService: WorkspaceService | ||
) { } | ||
|
||
canActivate( | ||
route: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { | ||
|
||
const workspaceId = this.workspaceService.getWorkspaceId(); | ||
|
||
if (!workspaceId) { | ||
return this.router.navigateByUrl(`workspaces`); | ||
} | ||
|
||
return forkJoin( | ||
[ | ||
this.xeroConnectorService.getXeroCredentials(workspaceId), | ||
this.xeroConnectorService.getXeroTokenHealth(workspaceId) | ||
] | ||
).pipe( | ||
map(response => !!response), | ||
catchError(error => { | ||
if (error.status === 400) { | ||
globalCacheBusterNotifier.next(); | ||
this.toastService.displayToastMessage(ToastSeverity.ERROR, 'Oops! Your Xero connection expired, please connect again'); | ||
|
||
const onboardingState: XeroOnboardingState = this.workspaceService.getOnboardingState(); | ||
|
||
return this.router.navigateByUrl('integrations/xero/onboarding/landing'); | ||
} | ||
|
||
return throwError(error); | ||
}) | ||
); | ||
} | ||
|
||
} |
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
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 @@ | ||
export type XeroCredentials = { | ||
id: number; | ||
refresh_token: string; | ||
company_name: string; | ||
country: string; | ||
created_at: Date; | ||
updated_at: Date; | ||
workspace: number; | ||
}; |
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 { PaginatedResponse } from "../../db/paginated-response.model"; | ||
import { TaskLog } from "../../db/task-log.model"; | ||
import { XeroTaskLogType } from "../../enum/enum.model"; | ||
|
||
export type XeroError = { | ||
expense_group_id: number; | ||
short_description: string; | ||
long_description: string; | ||
type: string; | ||
}; | ||
|
||
export interface XeroTaskLogs extends TaskLog { | ||
bill: number; | ||
cheque: number; | ||
credit_card_purchase: number; | ||
xero_errors: XeroError[]; | ||
journal_entry: number; | ||
bill_payment: number; | ||
task_id: string; | ||
type: XeroTaskLogType; | ||
} | ||
|
||
export interface XeroTaskResponse extends PaginatedResponse { | ||
results: Task[]; | ||
} |
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,15 @@ | ||
/* Tslint:disable */ | ||
export type TenantMapping = { | ||
id: number; | ||
tenant_name: string; | ||
tenant_id: string; | ||
connection_id: string; | ||
created_at: Date; | ||
updated_at: Date; | ||
workspace: number; | ||
}; | ||
|
||
export type TenantMappingPost = { | ||
tenant_id: string; | ||
tenant_name: string; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/app/core/models/xero/db/xero-workspace-general-setting.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,22 @@ | ||
export type XeroWorkspaceGeneralSetting = { | ||
id?: number; | ||
reimbursable_expenses_object: string; | ||
corporate_credit_card_expenses_object: string; | ||
import_projects?: boolean; | ||
import_categories: boolean; | ||
charts_of_accounts: string[]; | ||
change_accounting_period: boolean; | ||
sync_fyle_to_xero_payments: boolean; | ||
sync_xero_to_fyle_payments: boolean; | ||
map_merchant_to_contact: boolean; | ||
auto_map_employees: string; | ||
auto_create_destination_entity: boolean; | ||
is_simplify_report_closure_enabled: boolean; | ||
skip_cards_mapping?: boolean; | ||
import_tax_codes: boolean; | ||
import_customers: boolean; | ||
import_suppliers_as_merchants: boolean; | ||
created_at?: Date; | ||
updated_at?: Date; | ||
workspace?: number; | ||
}; |
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,14 @@ | ||
import { Workspace } from "../../db/workspaces.model"; | ||
import { XeroOnboardingState } from "../../enum/enum.model"; | ||
|
||
export interface XeroWorkspace extends Workspace { | ||
onboarding_state: XeroOnboardingState; | ||
fyle_currency: string; | ||
xero_currency: string; | ||
fyle_org_id: string; | ||
xero_short_code: string; | ||
last_synced_at?: Date; | ||
ccc_last_synced_at: Date; | ||
source_synced_at: Date; | ||
destination_synced_at: Date; | ||
} |
Oops, something went wrong.