Skip to content

Commit

Permalink
feat: Replace ExtendedProject -> ProjectV2 (#2923)
Browse files Browse the repository at this point in the history
  • Loading branch information
SahilK-027 authored May 3, 2024
1 parent 137861e commit 322061d
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 87 deletions.
4 changes: 2 additions & 2 deletions src/app/core/mock-data/recently-used.data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RecentlyUsed } from '../models/v1/recently_used.model';
import { ExtendedProject } from '../models/v2/extended-project.model';
import { ProjectV2 } from '../models/v2/project-v2.model';
import { Currency, CurrencyName } from '../models/currency.model';
import { CostCenter } from '../models/v1/cost-center.model';

Expand All @@ -26,7 +26,7 @@ export const recentlyUsedRes: RecentlyUsed = {
],
};

export const recentlyUsedProjectRes: ExtendedProject[] = [
export const recentlyUsedProjectRes: ProjectV2[] = [
{
ap1_email: '[email protected]',
ap1_full_name: 'John Doe',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AdvanceRequestCustomFieldValues } from './advance-request-custom-field-values.model';
import { CurrencyObj } from './currency-obj.model';
import { ExtendedProject } from './v2/extended-project.model';
import { ProjectV2 } from './v2/project-v2.model';

export interface AddEditAdvanceRequestFormValue {
currencyObj: CurrencyObj;
purpose: string;
notes: string;
project: ExtendedProject;
project: ProjectV2;
customFieldValues: AdvanceRequestCustomFieldValues[];
}
4 changes: 2 additions & 2 deletions src/app/core/models/mileage-form-value.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PlatformMileageRates } from './platform/platform-mileage-rates.model';
import { TxnCustomProperties } from './txn-custom-properties.model';
import { CostCenter } from './v1/cost-center.model';
import { OrgCategory } from './v1/org-category.model';
import { ExtendedProject } from './v2/extended-project.model';
import { ProjectV2 } from './v2/project-v2.model';
import { Report } from '../models/platform/v1/report.model';

export interface MileageFormValue {
Expand All @@ -22,7 +22,7 @@ export interface MileageFormValue {
mileage_rate_name: PlatformMileageRates;
vehicle_type: string;
dateOfSpend: Date;
project: ExtendedProject;
project: ProjectV2;
costCenter: CostCenter;
billable: boolean;
purpose: string;
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/models/per-diem-form-value.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TxnCustomProperties } from './txn-custom-properties.model';
import { CostCenter } from './v1/cost-center.model';
import { OrgCategory } from './v1/org-category.model';
import { PerDiemRates } from './v1/per-diem-rates.model';
import { ExtendedProject } from './v2/extended-project.model';
import { ProjectV2 } from './v2/project-v2.model';

export interface PerDiemFormValue {
currencyObj: {
Expand All @@ -15,7 +15,7 @@ export interface PerDiemFormValue {
orig_amount: number;
};
paymentMode: ExtendedAccount;
project: ExtendedProject;
project: ProjectV2;
sub_category: OrgCategory;
purpose: string;
num_days: number;
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/models/project-options.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ExtendedProject } from './v2/extended-project.model';
import { ProjectV2 } from './v2/project-v2.model';

export interface ProjectOption {
label: string;
value: ExtendedProject;
value: ProjectV2;
selected?: boolean;
}
4 changes: 2 additions & 2 deletions src/app/core/models/split-expense.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExtendedProject } from './v2/extended-project.model';
import { ProjectV2 } from './v2/project-v2.model';

export interface SplitExpense {
amount: number;
Expand All @@ -17,7 +17,7 @@ export interface SplitExpense {
sub_category: string;
updated_at: string;
};
project?: ExtendedProject;
project?: ProjectV2;
cost_center?: {
id: number;
created_at: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface ExtendedProject {
export interface ProjectV2 {
ap1_email: string;
ap1_full_name: string;
ap2_email: string;
Expand Down
33 changes: 15 additions & 18 deletions src/app/core/services/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ApiV2Service } from './api-v2.service';
import { map } from 'rxjs/operators';
import { Cacheable } from 'ts-cacheable';
import { Observable } from 'rxjs';
import { ExtendedProject } from '../models/v2/extended-project.model';
import { ProjectV2 } from '../models/v2/project-v2.model';
import { ProjectV1 } from '../models/v1/extended-project.model';
import { ProjectParams } from '../models/project-params.model';
import { intersection } from 'lodash';
Expand All @@ -14,10 +14,7 @@ import { OrgCategory } from '../models/v1/org-category.model';
providedIn: 'root',
})
export class ProjectsService {
constructor(
private apiService: ApiService,
private apiV2Service: ApiV2Service,
) {}
constructor(private apiService: ApiService, private apiV2Service: ApiV2Service) {}

@Cacheable()
getByParamsUnformatted(
Expand All @@ -31,8 +28,8 @@ export class ProjectsService {
sortOrder: string;
sortDirection: string;
projectIds: number[];
}>,
): Observable<ExtendedProject[]> {
}>
): Observable<ProjectV2[]> {
// eslint-disable-next-line prefer-const
let { orgId, active, orgCategoryIds, searchNameText, limit, offset, sortOrder, sortDirection, projectIds } =
projectParams;
Expand All @@ -59,7 +56,7 @@ export class ProjectsService {
this.addNameSearchFilter(searchNameText, params);

return this.apiV2Service
.get<ExtendedProject, {}>('/projects', {
.get<ProjectV2, {}>('/projects', {
params,
})
.pipe(
Expand All @@ -68,8 +65,8 @@ export class ProjectsService {
...datum,
project_created_at: new Date(datum.project_created_at),
project_updated_at: new Date(datum.project_updated_at),
})),
),
}))
)
);
}

Expand All @@ -86,7 +83,7 @@ export class ProjectsService {
}
});
return filterdProjects.length;
}),
})
);
}

Expand Down Expand Up @@ -114,7 +111,7 @@ export class ProjectsService {
}
}

getAllowedOrgCategoryIds(project: ProjectParams | ExtendedProject, activeCategoryList: OrgCategory[]): OrgCategory[] {
getAllowedOrgCategoryIds(project: ProjectParams | ProjectV2, activeCategoryList: OrgCategory[]): OrgCategory[] {
let categoryList: OrgCategory[] = [];
if (project) {
categoryList = activeCategoryList.filter((category: OrgCategory) => {
Expand Down Expand Up @@ -142,14 +139,14 @@ export class ProjectsService {
...datum,
created_at: new Date(datum.created_at),
updated_at: new Date(datum.updated_at),
})),
),
}))
)
);
}

getbyId(projectId: number | string): Observable<ExtendedProject> {
getbyId(projectId: number | string): Observable<ProjectV2> {
return this.apiV2Service
.get<ExtendedProject, {}>('/projects', {
.get<ProjectV2, {}>('/projects', {
params: {
project_id: `eq.${projectId}`,
},
Expand All @@ -161,8 +158,8 @@ export class ProjectsService {
...datum,
project_created_at: new Date(datum.project_created_at),
project_updated_at: new Date(datum.project_updated_at),
}))[0],
),
}))[0]
)
);
}
}
19 changes: 8 additions & 11 deletions src/app/core/services/recently-used-items.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ import { RecentlyUsed } from '../models/v1/recently_used.model';
import { ApiService } from './api.service';
import { ProjectsService } from 'src/app/core/services/projects.service';
import { map } from 'rxjs/operators';
import { ExtendedProject } from '../models/v2/extended-project.model';
import { ProjectV2 } from '../models/v2/project-v2.model';
import { ExtendedOrgUser } from '../models/extended-org-user.model';
import { OrgCategoryListItem } from '../models/v1/org-category.model';
import { Currency, CurrencyName } from '../models/currency.model';
@Injectable({
providedIn: 'root',
})
export class RecentlyUsedItemsService {
constructor(
private apiService: ApiService,
private projectService: ProjectsService,
) {}
constructor(private apiService: ApiService, private projectService: ProjectsService) {}

getRecentlyUsed(): Observable<RecentlyUsed> {
return this.apiService.get('/recently_used');
Expand All @@ -26,7 +23,7 @@ export class RecentlyUsedItemsService {
recentValues: RecentlyUsed;
eou: ExtendedOrgUser;
categoryIds: string[];
}): Observable<ExtendedProject[]> {
}): Observable<ProjectV2[]> {
if (
config.recentValues &&
config.recentValues.recent_project_ids &&
Expand All @@ -46,12 +43,12 @@ export class RecentlyUsedItemsService {
})
.pipe(
map((project) => {
const projectsMap: { [key: string]: ExtendedProject } = {};
const projectsMap: { [key: string]: ProjectV2 } = {};
project.forEach((item) => {
projectsMap[item.project_id] = item;
});
return config.recentValues.recent_project_ids.map((id) => projectsMap[id]).filter((id) => id);
}),
})
);
} else {
return of(null);
Expand All @@ -60,7 +57,7 @@ export class RecentlyUsedItemsService {

getRecentCostCenters(
costCenters: CostCenters[],
recentValue: RecentlyUsed,
recentValue: RecentlyUsed
): Observable<{ label: string; value: CostCenter; selected?: boolean }[]> {
if (
costCenters &&
Expand All @@ -78,7 +75,7 @@ export class RecentlyUsedItemsService {
.filter((id) => id);
if (recentCostCenterList.length > 0) {
return of(
recentCostCenterList.map((costCenter) => ({ label: costCenter.value.name, value: costCenter.value })),
recentCostCenterList.map((costCenter) => ({ label: costCenter.value.name, value: costCenter.value }))
);
} else {
return of(null);
Expand All @@ -90,7 +87,7 @@ export class RecentlyUsedItemsService {

getRecentCategories(
filteredCategories: OrgCategoryListItem[],
recentValues: RecentlyUsed,
recentValues: RecentlyUsed
): Observable<OrgCategoryListItem[]> {
if (
filteredCategories &&
Expand Down
6 changes: 3 additions & 3 deletions src/app/core/test-data/projects.spec.data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ProjectParams } from '../models/project-params.model';
import { ProjectV1 } from '../models/v1/extended-project.model';
import { OrgCategory, OrgCategoryListItem } from '../models/v1/org-category.model';
import { ExtendedProject } from '../models/v2/extended-project.model';
import { ProjectV2 } from '../models/v2/project-v2.model';

export const apiResponseActiveOnly = [
{
Expand Down Expand Up @@ -315,7 +315,7 @@ export const allowedActiveCategoriesListOptions: OrgCategoryListItem[] = [
},
];

export const expectedProjectsResponse: ExtendedProject[] = [
export const expectedProjectsResponse: ProjectV2[] = [
{
ap1_email: null,
ap1_full_name: null,
Expand Down Expand Up @@ -368,7 +368,7 @@ export const testProjectParams: ProjectParams = {
searchNameText: 'search',
};

export const testProjectV2: ExtendedProject = {
export const testProjectV2: ProjectV2 = {
ap1_email: null,
ap1_full_name: null,
ap2_email: null,
Expand Down
20 changes: 10 additions & 10 deletions src/app/fyle/add-edit-expense/add-edit-expense.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ import { OrgCategory, OrgCategoryListItem } from 'src/app/core/models/v1/org-cat
import { RecentlyUsed } from 'src/app/core/models/v1/recently_used.model';
import { Transaction } from 'src/app/core/models/v1/transaction.model';
import { DuplicateSet } from 'src/app/core/models/v2/duplicate-sets.model';
import { ExtendedProject } from 'src/app/core/models/v2/extended-project.model';
import { ProjectV2 } from 'src/app/core/models/v2/project-v2.model';
import { AccountsService } from 'src/app/core/services/accounts.service';
import { AuthService } from 'src/app/core/services/auth.service';
import { CategoriesService } from 'src/app/core/services/categories.service';
Expand Down Expand Up @@ -144,7 +144,7 @@ type FormValue = {
orig_amount: number;
};
paymentMode: ExtendedAccount;
project: ExtendedProject;
project: ProjectV2;
category: OrgCategory;
dateOfSpend: Date;
vendor_id: {
Expand Down Expand Up @@ -333,13 +333,13 @@ export class AddEditExpensePage implements OnInit {

orgUserSettings$: Observable<OrgUserSettings>;

recentProjects: { label: string; value: ExtendedProject; selected?: boolean }[];
recentProjects: { label: string; value: ProjectV2; selected?: boolean }[];

recentCurrencies: Currency[];

presetProjectId: number | string;

recentlyUsedProjects$: Observable<ExtendedProject[]>;
recentlyUsedProjects$: Observable<ProjectV2[]>;

recentlyUsedCurrencies$: Observable<Currency[]>;

Expand Down Expand Up @@ -411,7 +411,7 @@ export class AddEditExpensePage implements OnInit {

dependentFields$: Observable<ExpenseField[]>;

selectedProject$: BehaviorSubject<ExtendedProject | null>;
selectedProject$: BehaviorSubject<ProjectV2 | null>;

selectedCostCenter$: BehaviorSubject<CostCenter | null>;

Expand Down Expand Up @@ -1441,7 +1441,7 @@ export class AddEditExpensePage implements OnInit {
);
}

getSelectedProjects(): Observable<ExtendedProject> {
getSelectedProjects(): Observable<ProjectV2> {
return this.etxn$.pipe(
switchMap((etxn) => {
if (etxn.tx.project_id) {
Expand Down Expand Up @@ -1544,7 +1544,7 @@ export class AddEditExpensePage implements OnInit {
);
}

getRecentProjects(): Observable<ExtendedProject[]> {
getRecentProjects(): Observable<ProjectV2[]> {
return forkJoin({
recentValues: this.recentlyUsedValues$,
eou: this.authService.getEou(),
Expand Down Expand Up @@ -2546,7 +2546,7 @@ export class AddEditExpensePage implements OnInit {
}
}),
startWith(initialProject),
concatMap((project: ExtendedProject) =>
concatMap((project: ProjectV2) =>
activeCategories$.pipe(
map((activeCategories) => this.projectsService.getAllowedOrgCategoryIds(project, activeCategories))
)
Expand Down Expand Up @@ -2715,7 +2715,7 @@ export class AddEditExpensePage implements OnInit {
this.onPageExit$ = new Subject();
this.projectDependentFieldsRef?.ngOnInit();
this.costCenterDependentFieldsRef?.ngOnInit();
this.selectedProject$ = new BehaviorSubject<ExtendedProject>(null);
this.selectedProject$ = new BehaviorSubject<ProjectV2>(null);
this.selectedCostCenter$ = new BehaviorSubject<CostCenter>(null);
const fn = (): void => {
this.showClosePopup();
Expand All @@ -2727,7 +2727,7 @@ export class AddEditExpensePage implements OnInit {
setupSelectedProjectObservable(): void {
this.fg.controls.project.valueChanges
.pipe(takeUntil(this.onPageExit$))
.subscribe((project: ExtendedProject) => this.selectedProject$.next(project));
.subscribe((project: ProjectV2) => this.selectedProject$.next(project));
}

setupSelectedCostCenterObservable(): void {
Expand Down
Loading

0 comments on commit 322061d

Please sign in to comment.