From 246ff2de719d04386f938c73aabd26e22a2c616b Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Tue, 16 Apr 2024 11:27:35 +0530 Subject: [PATCH] feat: Move advance req get to platform API (#2854) --- .../core/mock-data/advance-platform.data.ts | 88 ++++++ ...dvance-request-custom-field-values.data.ts | 21 +- src/app/core/mock-data/approval.data.ts | 9 + .../extended-advance-request.data.ts | 218 ++++++++++++--- .../core/mock-data/extended-advance.data.ts | 168 +++++++----- .../core/mock-data/modal-controller.data.ts | 2 +- .../v1/advance-request-platform.data.ts | 114 ++++++++ .../stats-dimension-response.data.ts | 1 + .../unflattened-advance-request.data.ts | 2 - .../models/advance-request-state.model.ts | 9 + src/app/core/models/approval-public.model.ts | 5 + .../extended-advance-request-public.model.ts | 42 +++ src/app/core/models/extended_advance.model.ts | 31 +-- .../advance-request-platform.model.ts | 37 +++ .../platform/advances-platform.model.ts | 44 +++ .../models/platform/custom-fields.model.ts | 2 +- .../platform/platform-approval.model.ts | 7 + .../models/platform/platform-config.model.ts | 7 + .../platform/platform-employee.model.ts | 12 + .../models/platform/v1/department.model.ts | 16 +- .../platform/v1/platform-advance.model.ts | 7 + .../core/models/platform/v1/project.model.ts | 18 +- .../services/advance-request.service.spec.ts | 255 +++++++++++++++--- .../core/services/advance-request.service.ts | 160 ++++++++++- src/app/core/services/advance.service.spec.ts | 62 ++--- src/app/core/services/advance.service.ts | 104 ++++--- src/app/core/services/tasks.service.ts | 4 - src/app/core/services/utility.service.spec.ts | 38 +-- src/app/core/services/utility.service.ts | 7 +- .../add-edit-advance-request-2.page.spec.ts | 3 - .../add-edit-advance-request.page.ts | 6 +- .../dashboard/tasks/tasks-2.component.spec.ts | 13 +- .../tasks/tasks.component.setup.spec.ts | 2 +- .../fyle/dashboard/tasks/tasks.component.ts | 5 +- .../fyle/my-advances/my-advances.page.spec.ts | 146 +++++----- src/app/fyle/my-advances/my-advances.page.ts | 47 ++-- .../my-view-advance-request.page.spec.ts | 33 ++- .../my-view-advance-request.page.ts | 16 +- 38 files changed, 1326 insertions(+), 435 deletions(-) create mode 100644 src/app/core/mock-data/advance-platform.data.ts create mode 100644 src/app/core/mock-data/platform/v1/advance-request-platform.data.ts create mode 100644 src/app/core/models/advance-request-state.model.ts create mode 100644 src/app/core/models/approval-public.model.ts create mode 100644 src/app/core/models/extended-advance-request-public.model.ts create mode 100644 src/app/core/models/platform/advance-request-platform.model.ts create mode 100644 src/app/core/models/platform/advances-platform.model.ts create mode 100644 src/app/core/models/platform/platform-approval.model.ts create mode 100644 src/app/core/models/platform/platform-config.model.ts create mode 100644 src/app/core/models/platform/platform-employee.model.ts create mode 100644 src/app/core/models/platform/v1/platform-advance.model.ts diff --git a/src/app/core/mock-data/advance-platform.data.ts b/src/app/core/mock-data/advance-platform.data.ts new file mode 100644 index 0000000000..886398bd3c --- /dev/null +++ b/src/app/core/mock-data/advance-platform.data.ts @@ -0,0 +1,88 @@ +import { CustomFieldTypes } from '../enums/platform/v1/custom-fields-type.enum'; +import { AdvancesPlatform } from '../models/platform/advances-platform.model'; +import { PlatformApiResponse } from '../models/platform/platform-api-response.model'; + +export const advancePlatform: PlatformApiResponse = { + count: 1, + offset: 0, + data: [ + { + advance_account_id: 'accmwN4nDBMXM', + advance_request_id: 'areqrttywiidF8', + advance_wallet_id: null, + amount: 5044, + card_number: null, + code: null, + created_at: new Date('2024-03-11T08:32:40.861889+00:00'), + creator_user: { + email: 'neeraj.durgapal@fyle.in', + full_name: 'Neeraj D', + id: 'us1ymEVgUKqb', + }, + currency: 'INR', + custom_fields: [ + { + name: '123', + type: CustomFieldTypes.TEXT, + value: null, + }, + { + name: 'Project Name', + type: CustomFieldTypes.TEXT, + value: null, + }, + ], + employee: { + code: '1223', + department: { + code: null, + display_name: 'mileage dept / arun', + id: 'dept62zPkMskdX', + name: 'mileage dept', + sub_department: 'arun', + }, + department_id: 'dept62zPkMskdX', + id: 'ouX8dwsbLCLv', + org_id: 'orNVthTo2Zyo', + user: { + email: 'ajain@fyle.in', + full_name: 'Abhishek Jain test', + id: 'usvKA4X8Ugcr', + }, + user_id: 'usvKA4X8Ugcr', + }, + employee_id: 'ouX8dwsbLCLv', + foreign_amount: null, + foreign_currency: null, + id: 'advRhdN9D326Y', + is_exported: false, + issued_at: new Date('2024-03-11T08:32:27.449000+00:00'), + last_exported_at: null, + org_id: 'orNVthTo2Zyo', + payment_mode: 'CASH', + project: { + code: null, + display_name: 'AAAO2683 / TE02257 AURI', + id: 317383, + name: 'AAAO2683 / TE02257 AURI', + sub_project: null, + }, + project_id: '317383', + purpose: 'testing', + seq_num: 'A/2024/03/T/1', + settlement_id: null, + source: 'WEBAPP', + updated_at: new Date('2024-03-11T08:32:40.861889+00:00'), + user: { + email: 'ajain@fyle.in', + full_name: 'Abhishek Jain test', + id: 'usvKA4X8Ugcr', + }, + user_id: 'usvKA4X8Ugcr', + advance_request: { + id: 'areq1234', + last_approved_at: new Date('2024-03-14T08:32:40.861Z'), + }, + }, + ], +}; diff --git a/src/app/core/mock-data/advance-request-custom-field-values.data.ts b/src/app/core/mock-data/advance-request-custom-field-values.data.ts index 5f117f659d..497a2a1cbc 100644 --- a/src/app/core/mock-data/advance-request-custom-field-values.data.ts +++ b/src/app/core/mock-data/advance-request-custom-field-values.data.ts @@ -2,39 +2,42 @@ import { AdvanceRequestCustomFieldValues } from '../models/advance-request-custo export const advanceRequestCustomFieldValuesData: AdvanceRequestCustomFieldValues[] = [ { - id: 1302, name: 'Phase', value: 'Phase 1', type: 'SELECT', }, { - id: 1305, name: 'BILLABLE', value: true, type: 'BOOLEAN', }, { - id: 1304, name: 'Arrival Date', - value: '2 Jan 2023', + value: '2023-1-2', type: 'DATE', }, + { + name: 'Checking', + value: 'option1', + type: 'OPTION', + }, ]; export const advanceRequestCustomFieldValuesData2: AdvanceRequestCustomFieldValues[] = [ { - id: 1302, name: 'Phase', value: 'Phase 1', }, { - id: 1304, + name: 'BILLABLE', + value: true, + }, + { name: 'Arrival Date', value: '2023-1-2', }, { - id: 1305, - name: 'BILLABLE', - value: true, + name: 'Checking', + value: 'option1', }, ]; diff --git a/src/app/core/mock-data/approval.data.ts b/src/app/core/mock-data/approval.data.ts index 8af90dab47..64681f81f1 100644 --- a/src/app/core/mock-data/approval.data.ts +++ b/src/app/core/mock-data/approval.data.ts @@ -1,3 +1,4 @@ +import { ApprovalPublic } from '../models/approval-public.model'; import { Approval } from '../models/approval.model'; export const advanceReqApprovals: Approval[] = [ @@ -16,3 +17,11 @@ export const advanceReqApprovals: Approval[] = [ comment: null, }, ]; + +export const advanceReqApprovalsPublic: ApprovalPublic[] = [ + { + state: 'APPROVAL_PENDING', + approver_email: 'john.doe@example.com', + approver_name: 'John Doe', + }, +]; diff --git a/src/app/core/mock-data/extended-advance-request.data.ts b/src/app/core/mock-data/extended-advance-request.data.ts index a88c58bd16..ec6281ac0b 100644 --- a/src/app/core/mock-data/extended-advance-request.data.ts +++ b/src/app/core/mock-data/extended-advance-request.data.ts @@ -1,4 +1,6 @@ +import { cloneDeep } from 'lodash'; import { ApiV2Response } from '../models/api-v2.model'; +import { ExtendedAdvanceRequestPublic } from '../models/extended-advance-request-public.model'; import { ExtendedAdvanceRequest } from '../models/extended_advance_request.model'; export const singleExtendedAdvReqRes: ApiV2Response = { @@ -247,51 +249,40 @@ export const withoutDatesAdv = { us_full_name: 'Abhishek Jain', }; -export const singleErqRes: ExtendedAdvanceRequest = { - areq_id: 'areqGzKF1Tne23', - areq_created_at: new Date('2023-02-23T13:16:15.260Z'), - areq_approved_at: null, - areq_purpose: 'some', - areq_notes: null, - areq_state: 'SUBMITTED', +export const singleErqRes: ExtendedAdvanceRequestPublic = { + areq_advance_request_number: 'A/2020/10/T/95', + areq_advance_id: 'advjrgwlk2Q', + areq_amount: 47.99, + areq_approved_at: new Date('2020-06-14T13:14:55.201Z'), + areq_created_at: new Date('2020-06-01T13:14:54.804Z'), areq_currency: 'USD', - areq_amount: 100, - areq_org_user_id: 'ouX8dwsbLCLv', - areq_advance_id: null, - areq_policy_amount: null, - areq_policy_flag: null, - areq_policy_state: 'SUCCESS', - areq_project_id: null, - areq_custom_field_values: null, - areq_updated_at: new Date('2023-02-23T14:16:52.396Z'), - areq_source: 'MOBILE', - areq_advance_request_number: 'AR/2023/02/R/4', - areq_updated_by: null, - areq_is_sent_back: null, - areq_is_pulled_back: null, - ou_id: 'ouX8dwsbLCLv', - ou_org_id: 'orNVthTo2Zyo', - ou_org_name: 'Staging Loaded', - ou_employee_id: '', - ou_location: 'Mumbai', - ou_level: '123', - ou_business_unit: - 'A very long Business Unit indeed A very long Business Unit indeed A very long Business Unit indeed A very long Business Unit indeed', - ou_department: '0000000', - ou_title: 'director', - ou_mobile: '+12025559975', - ou_sub_department: null, - ou_department_id: 'deptpmQ0SsMO0S', - us_full_name: 'Abhishek Jain', - us_email: 'ajain@fyle.in', - project_code: null, - project_name: null, - advance_id: null, - us_name: 'Abhishek Jain', - policy_amount: null, - policy_flag: null, - policy_state: 'SUCCESS', - new_state: 'APPROVAL_PENDING', + areq_id: 'areqiwr3Wwirr', + areq_notes: 'onsite client meeting', + areq_org_user_id: 'outGt9ju6qP', + areq_project_id: '1234', + areq_purpose: 'onsite client meeting', + areq_source: 'WEBAPP', + areq_state: 'DRAFT', + areq_updated_at: new Date('2020-06-11T13:14:55.201Z'), + ou_department: 'Tech', + ou_department_id: 'deptCjFrZcE0rH', + ou_id: 'outGt9ju6qP', + ou_org_id: 'orwruogwnngg', + ou_sub_department: 'Tech', + us_email: 'john.doe@example.com', + us_full_name: 'John Doe', + areq_is_pulled_back: false, + ou_employee_id: 'outGt9ju6qP', + areq_custom_field_values: [ + { + name: 'checking', + value: 'true', + type: 'BOOLEAN', + }, + ], + areq_is_sent_back: false, + project_name: 'Fast and Furious', + project_code: 'C1234', }; export const singleErqUnflattened = { @@ -561,6 +552,145 @@ export const allAdvanceRequestsRes: ApiV2Response = { url: '/v2/advance_requests', }; +export const publicAdvanceRequestRes: ApiV2Response = { + count: 1, + data: [ + { + areq_advance_request_number: 'A/2020/10/T/95', + areq_advance_id: 'advjrgwlk2Q', + areq_amount: 47.99, + areq_approved_at: new Date('2020-06-14T13:14:55.201Z'), + areq_created_at: new Date('2020-06-01T13:14:54.804Z'), + areq_currency: 'USD', + areq_id: 'areqiwr3Wwirr', + areq_notes: 'onsite client meeting', + areq_org_user_id: 'outGt9ju6qP', + areq_project_id: '1234', + areq_purpose: 'onsite client meeting', + areq_source: 'WEBAPP', + areq_state: 'DRAFT', + areq_updated_at: new Date('2020-06-11T13:14:55.201Z'), + ou_department: 'Tech', + ou_department_id: 'deptCjFrZcE0rH', + ou_id: 'outGt9ju6qP', + ou_org_id: 'orwruogwnngg', + ou_sub_department: 'Tech', + us_email: 'john.doe@example.com', + us_full_name: 'John Doe', + areq_is_pulled_back: false, + ou_employee_id: 'outGt9ju6qP', + areq_custom_field_values: [{ name: 'checking', value: 'true', type: 'BOOLEAN' }], + areq_is_sent_back: false, + project_name: 'Fast and Furious', + project_code: 'C1234', + }, + ], + offset: 0, +}; + +export const publicAdvanceRequestResSentBack: ApiV2Response = { + count: 1, + data: [ + { + ...cloneDeep(publicAdvanceRequestRes.data[0]), + areq_state: 'INQUIRY', + areq_is_pulled_back: false, + areq_is_sent_back: true, + areq_id: 'areqiwr3Wwirk', + }, + ], + offset: 0, +}; + +export const publicAdvanceRequestResPulledBack: ApiV2Response = { + count: 1, + data: [ + { + ...cloneDeep(publicAdvanceRequestRes.data[0]), + areq_state: 'DRAFT', + areq_is_pulled_back: true, + areq_is_sent_back: false, + areq_id: 'areqiwr3Wwirl', + }, + ], + offset: 0, +}; + +export const publicAdvanceRequestRes2: ApiV2Response = { + ...publicAdvanceRequestRes, + count: 250, +}; + +export const publicAdvanceRequestRes3: ExtendedAdvanceRequestPublic = { + ...publicAdvanceRequestRes.data[0], + type: 'request', + currency: 'USD', + amount: 47.99, + created_at: new Date('2020-06-01T13:14:54.804Z'), + purpose: 'onsite client meeting', + state: 'DRAFT', + areq_is_pulled_back: true, +}; + +export const publicAdvanceRequestRes4: ExtendedAdvanceRequestPublic = { + ...publicAdvanceRequestRes.data[0], + type: 'request', + currency: 'USD', + amount: 47.99, + created_at: new Date('2020-06-01T13:14:54.804Z'), + purpose: 'onsite client meeting', + state: 'DRAFT', + areq_is_sent_back: true, +}; + +export const publicAdvanceRequestRes5: ApiV2Response = { + count: 1, + data: [ + { + areq_advance_request_number: 'A/2020/10/T/95', + areq_advance_id: 'advjrgwlk2Q', + areq_amount: 47.99, + areq_approved_at: new Date('2020-06-14T13:14:55.201Z'), + areq_created_at: new Date('2020-06-01T13:14:54.804Z'), + areq_currency: 'USD', + areq_id: 'areqiwr3Wwirr', + areq_notes: 'onsite client meeting', + areq_org_user_id: 'outGt9ju6qP', + areq_project_id: '1234', + areq_purpose: 'onsite client meeting', + areq_source: 'WEBAPP', + areq_state: 'DRAFT', + areq_updated_at: new Date('2020-06-11T13:14:55.201Z'), + ou_department: 'Tech', + ou_department_id: 'deptCjFrZcE0rH', + ou_id: 'outGt9ju6qP', + ou_org_id: 'orwruogwnngg', + ou_sub_department: 'Tech', + us_email: 'john.doe@example.com', + us_full_name: 'John Doe', + areq_is_pulled_back: true, + ou_employee_id: 'outGt9ju6qP', + areq_custom_field_values: [{ name: 'checking', value: 'true', type: 'BOOLEAN' }], + areq_is_sent_back: false, + project_name: 'Fast and Furious', + project_code: 'C1234', + }, + ], + offset: 0, +}; + +export const publicAdvanceRequestRes6: ExtendedAdvanceRequestPublic = { + ...publicAdvanceRequestRes.data[0], + type: 'request', + currency: 'USD', + amount: 47.99, + created_at: new Date('2020-06-01T13:14:54.804Z'), + purpose: 'onsite client meeting', + state: 'DRAFT', + areq_is_sent_back: false, + areq_is_pulled_back: true, +}; + export const allTeamAdvanceRequestsRes: ApiV2Response = { count: 43, data: [ diff --git a/src/app/core/mock-data/extended-advance.data.ts b/src/app/core/mock-data/extended-advance.data.ts index 9b108ebef8..b2d3644bc2 100644 --- a/src/app/core/mock-data/extended-advance.data.ts +++ b/src/app/core/mock-data/extended-advance.data.ts @@ -1,86 +1,61 @@ import { ExtendedAdvance } from '../models/extended_advance.model'; import { ApiV2Response } from '../models/api-v2.model'; +import { PlatformApiResponse } from '../models/platform/platform-api-response.model'; +import { AdvancesPlatform } from '../models/platform/advances-platform.model'; +import { CustomFieldTypes } from '../enums/platform/v1/custom-fields-type.enum'; export const singleExtendedAdvancesData: ApiV2Response = { count: 1, data: [ { - account_current_balance_amount: -12928.33, - account_id: 'acc37LwFcAIpg', - account_name: 'Advance Account', - account_target_balance_amount: 0, - account_tentative_balance_amount: -14948.33, - account_type: 'PERSONAL_ADVANCE_ACCOUNT', - adv_advance_number: 'A/2019/10/T/49', - adv_amount: 300, + adv_advance_number: 'A/2024/03/T/1', + adv_amount: 5044, adv_card_number: null, - adv_created_at: new Date('2019-10-31T04:36:01.927Z'), + adv_created_at: new Date('2024-03-11T08:32:40.861Z'), adv_currency: 'INR', adv_exported: false, - adv_id: 'advETmi3eePvQ', - adv_issued_at: new Date('2019-10-31T04:35:10.391Z'), - adv_mode: 'BANK_TRANSFER', + adv_id: 'advRhdN9D326Y', + adv_issued_at: new Date('2024-03-11T08:32:27.449Z'), + adv_mode: 'CASH', adv_orig_amount: null, adv_orig_currency: null, - adv_payment_id: 'payoMxfqFQXCO', - adv_purpose: 'New advance-2', + adv_purpose: 'testing', adv_refcode: null, - adv_settlement_id: 'setc2r9i3I2xr', + adv_settlement_id: null, adv_source: 'WEBAPP', - areq_approved_at: new Date('2019-10-31T04:35:46.866Z'), - areq_custom_field_values: '[{"id:64,"name:"test","value:null,"type:"NUMBER"}]', - areq_id: 'areqmq8cmnd5v4', - assignee_business_unit: null, - assignee_department_id: 'deptYSONXoGd64', - assignee_level_id: 'lvl7Lme2OI5FH', - assignee_ou_id: 'ourw7Hi4mmpO', + areq_id: 'areqrttywiidF8', + assignee_department_id: 'dept62zPkMskdX', + assignee_ou_id: 'ouX8dwsbLCLv', assignee_ou_org_id: 'orNVthTo2Zyo', - assignee_us_email: 'dimple.kh@fyle.in', - assignee_us_full_name: 'Dimple', - creator_ou_id: 'ouyrZ3cROTxu', - creator_ou_org_id: 'orNVthTo2Zyo', - creator_us_email: 'madhav.mansuriya@fyle.in', - creator_us_full_name: 'Madhav M', - custom_properties: { - test: null, - }, - ou_assignee_employee_id: 'abc', - ou_location: 'Mumbai', - ou_title: 'Outitle1', - project_code: 'Pc10wqpt', - project_id: null, - project_name: null, + assignee_us_email: 'ajain@fyle.in', + assignee_us_full_name: 'Abhishek Jain test', + project_code: null, + project_id: 317383, + project_name: 'AAAO2683 / TE02257 AURI', + type: 'advance', + creator_us_full_name: 'Neeraj D', + areq_approved_at: new Date('2024-03-14T08:32:40.861Z'), }, ], - limit: 1, offset: 0, - url: '/v2/advances', }; export const extendedAdvWithDates = { ...singleExtendedAdvancesData, adv_created_at: new Date('2019-10-31T04:36:01.927Z'), adv_issued_at: new Date('2019-10-31T04:35:10.391Z'), - areq_approved_at: new Date('2019-10-31T04:35:46.866Z'), }; export const extendedAdvWithoutDates = { ...singleExtendedAdvancesData, adv_created_at: '2019-10-31T04:36:01.927Z', adv_issued_at: '2019-10-31T04:35:10.391Z', - areq_approved_at: '2019-10-31T04:35:46.866Z', }; export const singleExtendedAdvancesData2: ApiV2Response = { count: 11, data: [ { - account_current_balance_amount: -12928.33, - account_id: 'acc37LwFcAIpg', - account_name: 'Advance Account', - account_target_balance_amount: 0, - account_tentative_balance_amount: -14948.33, - account_type: 'PERSONAL_ADVANCE_ACCOUNT', adv_advance_number: 'A/2019/10/T/49', adv_amount: 300, adv_card_number: null, @@ -92,34 +67,21 @@ export const singleExtendedAdvancesData2: ApiV2Response = { adv_mode: 'BANK_TRANSFER', adv_orig_amount: null, adv_orig_currency: null, - adv_payment_id: 'payoMxfqFQXCO', adv_purpose: 'New advance-2', adv_refcode: null, adv_settlement_id: 'setc2r9i3I2xr', adv_source: 'WEBAPP', - areq_approved_at: new Date('2019-10-31T04:35:46.866Z'), - areq_custom_field_values: '[{"id:64,"name:"test","value:null,"type:"NUMBER"}]', areq_id: 'areqmq8cmnd5v4', - assignee_business_unit: null, assignee_department_id: 'deptYSONXoGd64', - assignee_level_id: 'lvl7Lme2OI5FH', assignee_ou_id: 'ourw7Hi4mmpO', assignee_ou_org_id: 'orNVthTo2Zyo', assignee_us_email: 'dimple.kh@fyle.in', assignee_us_full_name: 'Dimple', - creator_ou_id: 'ouyrZ3cROTxu', - creator_ou_org_id: 'orNVthTo2Zyo', - creator_us_email: 'madhav.mansuriya@fyle.in', - creator_us_full_name: 'Madhav M', - custom_properties: { - test: null, - }, - ou_assignee_employee_id: 'abc', - ou_location: 'Mumbai', - ou_title: 'Outitle1', project_code: 'Pc10wqpt', project_id: null, project_name: null, + creator_us_full_name: 'Ajain', + areq_approved_at: new Date('2024-03-14T08:32:40.861Z'), }, ], limit: 1, @@ -130,10 +92,86 @@ export const singleExtendedAdvancesData2: ApiV2Response = { export const singleExtendedAdvancesData3: ExtendedAdvance = { ...singleExtendedAdvancesData.data[0], type: 'advance', - amount: 300, + amount: 5044, orig_amount: null, - created_at: new Date('2019-10-31T04:36:01.927Z'), + created_at: new Date('2024-03-11T08:32:40.861Z'), currency: 'INR', orig_currency: null, - purpose: 'New advance-2', + purpose: 'testing', +}; + +export const platformAdvanceData: PlatformApiResponse = { + count: 11, + offset: 200, + data: [ + { + advance_request_id: 'areqrttywiidF8', + amount: 5044, + card_number: null, + code: null, + created_at: new Date('2024-03-11T08:32:40.861889+00:00'), + creator_user: { + email: 'neeraj.durgapal@fyle.in', + full_name: 'Neeraj D', + id: 'us1ymEVgUKqb', + }, + currency: 'INR', + custom_fields: [ + { + name: '123', + type: CustomFieldTypes.TEXT, + value: null, + }, + ], + employee: { + code: '1223', + department: { + code: null, + display_name: 'mileage dept / arun', + id: 'dept62zPkMskdX', + name: 'mileage dept', + sub_department: 'arun', + }, + department_id: 'dept62zPkMskdX', + id: 'ouX8dwsbLCLv', + org_id: 'orNVthTo2Zyo', + user: { + email: 'ajain@fyle.in', + full_name: 'Abhishek Jain test', + id: 'usvKA4X8Ugcr', + }, + user_id: 'usvKA4X8Ugcr', + }, + employee_id: 'ouX8dwsbLCLv', + foreign_amount: null, + foreign_currency: null, + id: 'advRhdN9D326Y', + is_exported: false, + last_exported_at: null, + org_id: 'orNVthTo2Zyo', + payment_mode: 'CASH', + project: { + code: null, + display_name: 'AAAO2683 / TE02257 AURI', + id: 317383, + name: 'AAAO2683 / TE02257 AURI', + sub_project: null, + }, + project_id: '317383', + purpose: 'testing', + seq_num: 'A/2024/03/T/1', + settlement_id: null, + source: 'WEBAPP', + updated_at: new Date('2024-03-11T08:32:40.861889+00:00'), + issued_at: new Date('2024-03-11T08:32:40.861889+00:00'), + advance_account_id: null, + advance_wallet_id: null, + user: { + email: 'ajain@fyle.in', + full_name: 'Abhishek Jain test', + id: 'usvKA4X8Ugcr', + }, + user_id: 'usvKA4X8Ugcr', + }, + ], }; diff --git a/src/app/core/mock-data/modal-controller.data.ts b/src/app/core/mock-data/modal-controller.data.ts index f404ca377d..e165cfea06 100644 --- a/src/app/core/mock-data/modal-controller.data.ts +++ b/src/app/core/mock-data/modal-controller.data.ts @@ -502,7 +502,7 @@ export const modalControllerParams8 = { component: ViewCommentComponent, componentProps: { objectType: 'advance_requests', - objectId: 'areqoVuT5I8OOy', + objectId: 'areqiwr3Wwirr', }, cssClass: 'fy-modal', showBackdrop: true, diff --git a/src/app/core/mock-data/platform/v1/advance-request-platform.data.ts b/src/app/core/mock-data/platform/v1/advance-request-platform.data.ts new file mode 100644 index 0000000000..2d8a713e27 --- /dev/null +++ b/src/app/core/mock-data/platform/v1/advance-request-platform.data.ts @@ -0,0 +1,114 @@ +import { cloneDeep } from 'lodash'; +import { CustomFieldTypes } from 'src/app/core/enums/platform/v1/custom-fields-type.enum'; +import { AdvanceRequestState } from 'src/app/core/models/advance-request-state.model'; +import { AdvanceRequestPlatform } from 'src/app/core/models/platform/advance-request-platform.model'; +import { PlatformApiResponse } from 'src/app/core/models/platform/platform-api-response.model'; + +export const advanceRequestPlatform: PlatformApiResponse = { + count: 1, + offset: 0, + data: [ + { + advance: { + id: 'advkvnwrnpwi', + currency: 'USD', + amount: 47.99, + advance_request_id: 'advjrgwlk2Q', + seq_num: 'A/2020/10/T/95', + }, + id: 'areqiwr3Wwirr', + user_id: 'uswjwgnwwgo', + user: { + id: 'uswjwgnwwgo', + email: 'john.doe@example.com', + full_name: 'John Doe', + }, + approvals: [ + { + approver_user_id: 'usge49ielgel', + approver_user: { + id: 'uswjwgnwwgo', + email: 'john.doe@example.com', + full_name: 'John Doe', + }, + state: 'APPROVAL_PENDING', + }, + ], + org_id: 'orwruogwnngg', + created_at: new Date('2020-06-01T13:14:54.804+00:00'), + updated_at: new Date('2020-06-11T13:14:55.201598+00:00'), + currency: 'USD', + amount: 47.99, + policy_amount: 1500, + advance_id: 'advjrgwlk2Q', + seq_num: 'A/2020/10/T/95', + code: 'C1234', + notes: 'onsite client meeting', + purpose: 'onsite client meeting', + source: 'WEBAPP', + state: 'DRAFT', + project_id: '1234', + project: { + id: 1234, + name: 'Fast and Furious', + sub_project: 'Formula One', + code: 'C1234', + display_name: 'Fast and Furious / Formula One', + }, + is_policy_flagged: true, + is_exported: true, + employee_id: 'outGt9ju6qP', + employee: { + code: null, + department: { + code: null, + display_name: 'Tech', + id: 'deptCjFrZcE0rH', + name: 'Tech', + sub_department: 'Tech', + }, + department_id: 'deptCjFrZcE0rH', + id: 'ouirDZ7tTLEQ', + org_id: 'orNVthTo2Zyo', + user: { + email: 'arjun.m@fyle.in', + full_name: 'Arjun', + id: 'usJZ9bgfNB5n', + }, + user_id: 'usJZ9bgfNB5n', + }, + last_approved_at: new Date('2020-06-14T13:14:55.201598+00:00'), + custom_fields: [ + { + name: 'checking', + value: 'true', + type: CustomFieldTypes.BOOLEAN, + }, + ], + }, + ], +}; + +export const advanceRequestPlatformPulledBack: PlatformApiResponse = { + count: 1, + offset: 0, + data: [ + { + ...cloneDeep(advanceRequestPlatform.data[0]), + state: 'PULLED_BACK', + id: 'areqiwr3Wwirl', + }, + ], +}; + +export const advanceRequestPlatformSentBack: PlatformApiResponse = { + count: 1, + offset: 0, + data: [ + { + ...cloneDeep(advanceRequestPlatform.data[0]), + id: 'areqiwr3Wwirk', + state: 'SENT_BACK', + }, + ], +}; diff --git a/src/app/core/mock-data/stats-dimension-response.data.ts b/src/app/core/mock-data/stats-dimension-response.data.ts index 07f9451de4..0495023096 100644 --- a/src/app/core/mock-data/stats-dimension-response.data.ts +++ b/src/app/core/mock-data/stats-dimension-response.data.ts @@ -1,3 +1,4 @@ +import { PlatformApiResponse } from '../models/platform/platform-api-response.model'; import { StatsDimensionResponse } from '../models/stats-dimension-response.model'; import { ApiV2Response } from '../models/v2/api-v2-response.model'; diff --git a/src/app/core/mock-data/unflattened-advance-request.data.ts b/src/app/core/mock-data/unflattened-advance-request.data.ts index 0d122dcef0..5a40adfad3 100644 --- a/src/app/core/mock-data/unflattened-advance-request.data.ts +++ b/src/app/core/mock-data/unflattened-advance-request.data.ts @@ -18,13 +18,11 @@ export const unflattenedAdvanceRequestData: UnflattenedAdvanceRequest = { project_id: null, custom_field_values: [ { - id: 159, name: 'Advance Request Place', value: 'd', type: null, }, { - id: 160, name: 'Category', value: 'Fyle is best', type: null, diff --git a/src/app/core/models/advance-request-state.model.ts b/src/app/core/models/advance-request-state.model.ts new file mode 100644 index 0000000000..5d43cdab40 --- /dev/null +++ b/src/app/core/models/advance-request-state.model.ts @@ -0,0 +1,9 @@ +export const enum AdvanceRequestState { + SENT_BACK = 'SENT_BACK', + DRAFT = 'DRAFT', + APPROVAL_PENDING = 'APPROVAL_PENDING', + APPROVED = 'APPROVED', + PULLED_BACK = 'PULLED_BACK', + REJECTED = 'REJECTED', + PAID = 'PAID', +} diff --git a/src/app/core/models/approval-public.model.ts b/src/app/core/models/approval-public.model.ts new file mode 100644 index 0000000000..28957f5097 --- /dev/null +++ b/src/app/core/models/approval-public.model.ts @@ -0,0 +1,5 @@ +export interface ApprovalPublic { + approver_name: string; + approver_email: string; + state: string; +} diff --git a/src/app/core/models/extended-advance-request-public.model.ts b/src/app/core/models/extended-advance-request-public.model.ts new file mode 100644 index 0000000000..a0dfe950e6 --- /dev/null +++ b/src/app/core/models/extended-advance-request-public.model.ts @@ -0,0 +1,42 @@ +import { AdvanceRequestState } from './advance-request-state.model'; +import { CustomField } from './custom_field.model'; +import { PlatformApproval } from './platform/platform-approval.model'; + +export interface ExtendedAdvanceRequestPublic { + areq_advance_id: string; + areq_advance_request_number: string; + areq_amount: number; + areq_approved_at: Date; + areq_created_at: Date; + areq_currency: string; + areq_id: string; + areq_is_pulled_back: boolean; + areq_notes: string; + areq_org_user_id: string; + areq_project_id?: string; + advance_id?: string; + us_name?: string; + areq_purpose: string; + areq_source: string; + areq_state: string; + areq_updated_at: Date; + ou_department_id?: string; + ou_employee_id: string; + ou_id: string; + ou_org_id: string; + ou_department?: string; + ou_sub_department?: string; + us_email: string; + us_full_name: string; + areq_custom_field_values: CustomField[]; + areq_is_sent_back: boolean; + created_at?: Date; + project_name?: string; + type?: string; + currency?: string; + amount?: number; + purpose?: string; + state?: string; + project_code?: string; + adv_created_at?: Date; +} diff --git a/src/app/core/models/extended_advance.model.ts b/src/app/core/models/extended_advance.model.ts index 650e827dba..896b050657 100644 --- a/src/app/core/models/extended_advance.model.ts +++ b/src/app/core/models/extended_advance.model.ts @@ -1,54 +1,37 @@ +import { User } from './platform/v1/user.model'; + export interface ExtendedAdvance { - account_current_balance_amount: number; - account_id: string; - account_name: string; - account_target_balance_amount: number; - account_tentative_balance_amount: number; - account_type: string; adv_advance_number: string; adv_amount: number; adv_card_number: string; adv_created_at: Date; adv_currency: string; - adv_exported: false; + adv_exported: boolean; adv_id: string; adv_issued_at: Date; adv_mode: string; adv_orig_amount: number; adv_orig_currency: string; - adv_payment_id: string; adv_purpose: string; adv_refcode: string; adv_settlement_id: string; adv_source: string; - areq_approved_at: Date; - areq_custom_field_values: string; areq_id: string; - assignee_business_unit: string; assignee_department_id: string; - assignee_level_id: string; assignee_ou_id: string; assignee_ou_org_id: string; assignee_us_email: string; assignee_us_full_name: string; - creator_ou_id: string; - creator_ou_org_id: string; - creator_us_email: string; - creator_us_full_name: string; - custom_properties: { - [id: string | number]: boolean | string | number | string[]; - }; - ou_assignee_employee_id: string; - ou_location: string; - ou_title: string; project_code: string; project_id: number; project_name: string; type?: string; + created_at?: Date; amount?: number; orig_amount?: number; currency?: string; - purpose?: string; orig_currency?: string; - created_at?: Date; + purpose?: string; + creator_us_full_name: string; + areq_approved_at: Date; } diff --git a/src/app/core/models/platform/advance-request-platform.model.ts b/src/app/core/models/platform/advance-request-platform.model.ts new file mode 100644 index 0000000000..4baf9744e9 --- /dev/null +++ b/src/app/core/models/platform/advance-request-platform.model.ts @@ -0,0 +1,37 @@ +import { CustomFields } from './custom-fields.model'; +import { Project } from './v1/project.model'; +import { User } from '../user.model'; +import { PlatformEmployee } from './platform-employee.model'; +import { Department } from './v1/department.model'; +import { PlatformApproval } from './platform-approval.model'; +import { PlatformAdvance } from './v1/platform-advance.model'; +import { CustomField } from '../custom_field.model'; + +export interface AdvanceRequestPlatform { + advance: PlatformAdvance; + advance_id: string; + amount: number; + code: string; + created_at: Date; + currency: string; + approvals: PlatformApproval[]; + custom_fields: CustomField[]; + employee: PlatformEmployee; + employee_id: string; + id: string; + is_exported: boolean; + is_policy_flagged: boolean; + last_approved_at: Date; + notes: string; + org_id: string; + policy_amount: number; + project?: Project; + project_id?: string; + purpose: string; + seq_num: string; + source: string; + state: string; + updated_at: Date; + user: User; + user_id: string; +} diff --git a/src/app/core/models/platform/advances-platform.model.ts b/src/app/core/models/platform/advances-platform.model.ts new file mode 100644 index 0000000000..fa2c49ff10 --- /dev/null +++ b/src/app/core/models/platform/advances-platform.model.ts @@ -0,0 +1,44 @@ +import { CustomFields } from './custom-fields.model'; +import { Project } from './v1/project.model'; +import { PlatformEmployee } from './platform-employee.model'; +import { Department } from './v1/department.model'; +import { PlatformApproval } from './platform-approval.model'; +import { PlatformAdvance } from './v1/platform-advance.model'; +import { UserDetails } from '../v1/user-details.model'; +import { User } from './v1/user.model'; + +export interface AdvancesPlatform { + id: string; + user_id: string; + user: User; + org_id: string; + created_at: Date; + updated_at: Date; + currency: string; + amount: number; + foreign_currency: string; + foreign_amount: number; + payment_mode: string; + advance_request_id: string; + advance_account_id: string; + advance_wallet_id: string; + seq_num: string; + purpose: string; + source: string; + project_id: string; + project: Project; + code: string; + issued_at: Date; + card_number: string; + settlement_id: string; + is_exported: boolean; + last_exported_at: Date; + custom_fields: CustomFields[]; + employee_id: string; + employee: PlatformEmployee; + creator_user: User; + advance_request?: { + id: string; + last_approved_at: Date; + }; +} diff --git a/src/app/core/models/platform/custom-fields.model.ts b/src/app/core/models/platform/custom-fields.model.ts index 2485327354..d61e23fd36 100644 --- a/src/app/core/models/platform/custom-fields.model.ts +++ b/src/app/core/models/platform/custom-fields.model.ts @@ -4,5 +4,5 @@ export interface CustomFields { name: string; value: string | string[] | boolean | number | Record; type: CustomFieldTypes; - is_enabled: boolean; + is_enabled?: boolean; } diff --git a/src/app/core/models/platform/platform-approval.model.ts b/src/app/core/models/platform/platform-approval.model.ts new file mode 100644 index 0000000000..9fd239308c --- /dev/null +++ b/src/app/core/models/platform/platform-approval.model.ts @@ -0,0 +1,7 @@ +import { User } from './v1/user.model'; + +export interface PlatformApproval { + approver_user_id: string; + approver_user: User; + state: string; +} diff --git a/src/app/core/models/platform/platform-config.model.ts b/src/app/core/models/platform/platform-config.model.ts new file mode 100644 index 0000000000..d31684ff1d --- /dev/null +++ b/src/app/core/models/platform/platform-config.model.ts @@ -0,0 +1,7 @@ +import { Filters } from '../filters.model'; + +export interface PlatformConfig { + offset: number; + limit: number; + queryParams?: Record; +} diff --git a/src/app/core/models/platform/platform-employee.model.ts b/src/app/core/models/platform/platform-employee.model.ts new file mode 100644 index 0000000000..cbf8b77956 --- /dev/null +++ b/src/app/core/models/platform/platform-employee.model.ts @@ -0,0 +1,12 @@ +import { User } from '../user.model'; +import { Department } from './v1/department.model'; + +export interface PlatformEmployee { + id: string; + user_id: string; + user: User; + code: string; + department?: Department; + department_id?: string; + org_id: string; +} diff --git a/src/app/core/models/platform/v1/department.model.ts b/src/app/core/models/platform/v1/department.model.ts index 648a30d9b4..3b9743108e 100644 --- a/src/app/core/models/platform/v1/department.model.ts +++ b/src/app/core/models/platform/v1/department.model.ts @@ -2,16 +2,16 @@ import { User } from './user.model'; export interface Department { id: string; - org_id: string; - created_at: Date; - updated_at: Date; - is_enabled: boolean; + org_id?: string; + created_at?: Date; + updated_at?: Date; + is_enabled?: boolean; name: string; code: string; - description: string; + description?: string; sub_department: string; - department_head_user_ids: string[]; - department_head_users: User[]; - doc_url: string; + department_head_user_ids?: string[]; + department_head_users?: User[]; + doc_url?: string; display_name: string; } diff --git a/src/app/core/models/platform/v1/platform-advance.model.ts b/src/app/core/models/platform/v1/platform-advance.model.ts new file mode 100644 index 0000000000..b7efabc445 --- /dev/null +++ b/src/app/core/models/platform/v1/platform-advance.model.ts @@ -0,0 +1,7 @@ +export interface PlatformAdvance { + id: string; + currency: string; + amount: number; + advance_request_id: string; + seq_num: string; +} diff --git a/src/app/core/models/platform/v1/project.model.ts b/src/app/core/models/platform/v1/project.model.ts index 75b05fb3a8..8787ea8cc1 100644 --- a/src/app/core/models/platform/v1/project.model.ts +++ b/src/app/core/models/platform/v1/project.model.ts @@ -2,17 +2,17 @@ import { User } from './user.model'; export interface Project { id: number; - org_id: string; - created_at: Date; - updated_at: Date; + org_id?: string; + created_at?: Date; + updated_at?: Date; name: string; sub_project: string; code: string; display_name: string; - description: string; - is_enabled: boolean; - restricted_spender_user_ids: string[]; - approver_user_ids: string[]; - approver_users: User[]; - category_ids: number[]; + description?: string; + is_enabled?: boolean; + restricted_spender_user_ids?: string[]; + approver_user_ids?: string[]; + approver_users?: User[]; + category_ids?: number[]; } diff --git a/src/app/core/services/advance-request.service.spec.ts b/src/app/core/services/advance-request.service.spec.ts index b88e2dcab7..fc58d6bdd3 100644 --- a/src/app/core/services/advance-request.service.spec.ts +++ b/src/app/core/services/advance-request.service.spec.ts @@ -12,7 +12,7 @@ import { pullBackAdvancedRequests, rejectedAdvReqRes, } from '../mock-data/advance-requests.data'; -import { advanceReqApprovals } from '../mock-data/approval.data'; +import { advanceReqApprovals, advanceReqApprovalsPublic } from '../mock-data/approval.data'; import { customField2, customFields, @@ -32,6 +32,9 @@ import { extendedAdvReqSubmitted, extendedAdvReqWithDates, extendedAdvReqWithoutDates, + publicAdvanceRequestRes, + publicAdvanceRequestResPulledBack, + publicAdvanceRequestResSentBack, singleErqRes, singleErqUnflattened, singleExtendedAdvReqRes, @@ -53,6 +56,12 @@ import { FileService } from './file.service'; import { OrgUserSettingsService } from './org-user-settings.service'; import { TimezoneService } from './timezone.service'; import { SpenderService } from './platform/v1/spender/spender.service'; +import { + advanceRequestPlatform, + advanceRequestPlatformPulledBack, + advanceRequestPlatformSentBack, +} from '../mock-data/platform/v1/advance-request-platform.data'; +import { cloneDeep } from 'lodash'; describe('AdvanceRequestService', () => { let advanceRequestService: AdvanceRequestService; @@ -74,7 +83,7 @@ describe('AdvanceRequestService', () => { const fileServiceSpy = jasmine.createSpyObj('FileService', ['post']); const orgUserSettingsServiceSpy = jasmine.createSpyObj('OrgUserSettingsService', ['get']); const timezoneServiceSpy = jasmine.createSpyObj('TimezoneService', ['convertToUtc']); - const spenderServiceSpy = jasmine.createSpyObj('SpenderService', ['post']); + const spenderServiceSpy = jasmine.createSpyObj('SpenderService', ['post', 'get']); TestBed.configureTestingModule({ providers: [ @@ -156,6 +165,74 @@ describe('AdvanceRequestService', () => { }); }); + describe('getAdvanceRequestPlatform(): ', () => { + it('should get an advance request from ID', (done) => { + const advReqID = 'areqiwr3Wwiri'; + const expectedData = cloneDeep(publicAdvanceRequestRes); + spenderService.get.and.returnValue(of(advanceRequestPlatform)); + // @ts-ignore + spyOn(advanceRequestService, 'fixDatesForPlatformFields').and.returnValue(advanceRequestPlatform.data[0]); + + advanceRequestService.getAdvanceRequestPlatform(advReqID).subscribe((res) => { + expect(res).toEqual(expectedData.data[0]); + expect(spenderService.get).toHaveBeenCalledOnceWith('/advance_requests', { + params: { + id: `eq.${advReqID}`, + }, + }); + // @ts-ignore + expect(advanceRequestService.fixDatesForPlatformFields).toHaveBeenCalledOnceWith( + advanceRequestPlatform.data[0] + ); + done(); + }); + }); + + it('should get a sent back advance request from ID', (done) => { + const advReqID = 'areqiwr3Wwirk'; + const expectedData = cloneDeep(publicAdvanceRequestResSentBack); + spenderService.get.and.returnValue(of(advanceRequestPlatformSentBack)); + // @ts-ignore + spyOn(advanceRequestService, 'fixDatesForPlatformFields').and.returnValue(advanceRequestPlatformSentBack.data[0]); + + advanceRequestService.getAdvanceRequestPlatform(advReqID).subscribe((res) => { + expect(res).toEqual(expectedData.data[0]); + expect(spenderService.get).toHaveBeenCalledOnceWith('/advance_requests', { + params: { + id: `eq.${advReqID}`, + }, + }); + // @ts-ignore + expect(advanceRequestService.fixDatesForPlatformFields).toHaveBeenCalledOnceWith( + advanceRequestPlatformSentBack.data[0] + ); + done(); + }); + }); + + it('should get a pulled back advance request from ID', (done) => { + const advReqID = 'areqiwr3Wwirr'; + const expectedData = cloneDeep(publicAdvanceRequestResPulledBack); + spenderService.get.and.returnValue(of(advanceRequestPlatformPulledBack)); + // @ts-ignore + spyOn(advanceRequestService, 'fixDatesForPlatformFields').and.returnValue(advanceRequestPlatformPulledBack.data[0]); + + advanceRequestService.getAdvanceRequestPlatform(advReqID).subscribe((res) => { + expect(res).toEqual(expectedData.data[0]); + expect(spenderService.get).toHaveBeenCalledOnceWith('/advance_requests', { + params: { + id: `eq.${advReqID}`, + }, + }); + // @ts-ignore + expect(advanceRequestService.fixDatesForPlatformFields).toHaveBeenCalledOnceWith( + advanceRequestPlatformPulledBack.data[0] + ); + done(); + }); + }); + }); + it('getActions(): should get advance request actions from ID', (done) => { const advReqID = 'areqoVuT5I8OOy'; apiService.get.and.returnValue(of(apiAdvanceRequestAction)); @@ -254,7 +331,6 @@ describe('AdvanceRequestService', () => { const params = { state: 'eq.SENT_BACK', }; - advanceRequestService.getAdvanceRequestStats(params).subscribe((res) => { expect(res).toEqual(statsResponse); expect(spenderService.post).toHaveBeenCalledOnceWith('/advance_requests/stats', { @@ -387,6 +463,13 @@ describe('AdvanceRequestService', () => { }); }); + it('fixDatesForPlatformFields(): should convert string values to dates', () => { + //@ts-ignore + expect(advanceRequestService.fixDatesForPlatformFields(advanceRequestPlatform.data[0])).toEqual( + advanceRequestPlatform.data[0] + ); + }); + it('getActiveApproversByAdvanceRequestId(): should get active approvers for an advance request', (done) => { const advID = 'areqa4CojbCAqd'; //@ts-ignore @@ -400,6 +483,20 @@ describe('AdvanceRequestService', () => { }); }); + it('getActiveApproversByAdvanceRequestId(): should get active approvers for an advance request', (done) => { + const advID = 'areqiwr3Wwirr'; + //@ts-ignore + spenderService.get.and.returnValue(of(advanceRequestPlatform)); + advanceRequestService.getActiveApproversByAdvanceRequestIdPlatform(advID).subscribe((res) => { + expect(res).toEqual(advanceReqApprovalsPublic); + //@ts-ignore + expect(spenderService.get).toHaveBeenCalledOnceWith('/advance_requests', { + params: { id: `eq.${advID}` }, + }); + done(); + }); + }); + it('getApproversByAdvanceRequestId(): should get approvers for an advance request', (done) => { apiService.get.and.returnValue(of(advanceReqApprovals)); const advID = 'areqa4CojbCAqd'; @@ -461,7 +558,7 @@ describe('AdvanceRequestService', () => { }); it('getEReq(): should get advance request', (done) => { - apiService.get.and.returnValue(of(singleErqRes)); + spyOn(advanceRequestService, 'getAdvanceRequestPlatform').and.returnValue(of(publicAdvanceRequestRes.data[0])); dataTransformService.unflatten.and.returnValue(singleErqUnflattened); spyOn(dateService, 'fixDates').and.returnValue(of(expectedSingleErq)); @@ -555,6 +652,128 @@ describe('AdvanceRequestService', () => { }); }); + describe('getSpenderAdvanceRequestsCount():', () => { + it('should get advance request count', (done) => { + spyOn(advanceRequestService, 'getSpenderAdvanceRequests').and.returnValue(of(publicAdvanceRequestRes)); + const queryParams = { + advance_id: 'eq.null', + }; + + advanceRequestService.getSpenderAdvanceRequestsCount(queryParams).subscribe((res) => { + expect(res).toEqual(publicAdvanceRequestRes.count); + expect(advanceRequestService.getSpenderAdvanceRequests).toHaveBeenCalledOnceWith({ + offset: 0, + limit: 1, + queryParams: { ...queryParams }, + }); + done(); + }); + }); + + it('should get advance request count without query parmas', (done) => { + spyOn(advanceRequestService, 'getSpenderAdvanceRequests').and.returnValue(of(publicAdvanceRequestRes)); + + advanceRequestService.getSpenderAdvanceRequestsCount().subscribe((res) => { + expect(res).toEqual(publicAdvanceRequestRes.count); + expect(advanceRequestService.getSpenderAdvanceRequests).toHaveBeenCalledOnceWith({ + offset: 0, + limit: 1, + queryParams: {}, + }); + done(); + }); + }); + }); + + describe('getSpenderAdvanceRequests():', () => { + it('should get all advance request', (done) => { + spenderService.get.and.returnValue(of(advanceRequestPlatform)); + + const param = { + offset: 0, + limit: 200, + queryParams: { + advance_id: 'eq.null', + order: 'created_at.desc,id.desc', + }, + }; + + advanceRequestService.getSpenderAdvanceRequests(param).subscribe((res) => { + expect(res).toEqual(publicAdvanceRequestRes); + expect(spenderService.get).toHaveBeenCalledOnceWith('/advance_requests', { + params: { + offset: param.offset, + limit: param.limit, + ...param.queryParams, + }, + }); + done(); + }); + }); + it('should get all advance request with default params', (done) => { + spenderService.get.and.returnValue(of(advanceRequestPlatform)); + + advanceRequestService.getSpenderAdvanceRequests().subscribe((res) => { + expect(res).toEqual(publicAdvanceRequestRes); + expect(spenderService.get).toHaveBeenCalledOnceWith('/advance_requests', { + params: { + offset: 0, + limit: 200, + advance_id: 'eq.null', + }, + }); + done(); + }); + }); + }); + + describe('getMyadvanceRequests():', () => { + it('should get all advance request', (done) => { + authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); + apiv2Service.get.and.returnValue(of(allAdvanceRequestsRes)); + + const param = { + offset: 0, + limit: 10, + queryParams: { + areq_advance_id: 'is.null', + order: 'areq_created_at.desc,areq_id.desc', + }, + }; + + advanceRequestService.getMyadvanceRequests(param).subscribe((res) => { + expect(res).toEqual(allAdvanceRequestsRes); + expect(apiv2Service.get).toHaveBeenCalledOnceWith('/advance_requests', { + params: { + offset: param.offset, + limit: param.limit, + areq_org_user_id: 'eq.' + apiEouRes.ou.id, + ...param.queryParams, + }, + }); + expect(authService.getEou).toHaveBeenCalledTimes(1); + done(); + }); + }); + it('should get all advance request with default params', (done) => { + authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); + apiv2Service.get.and.returnValue(of(allAdvanceRequestsRes)); + + advanceRequestService.getMyadvanceRequests().subscribe((res) => { + expect(res).toEqual(allAdvanceRequestsRes); + expect(apiv2Service.get).toHaveBeenCalledOnceWith('/advance_requests', { + params: { + offset: 0, + limit: 10, + areq_org_user_id: 'eq.' + apiEouRes.ou.id, + }, + }); + expect(authService.getEou).toHaveBeenCalledTimes(1); + done(); + }); + }); + }); + describe('getMyAdvanceRequestsCount():', () => { it('should get advance request count', (done) => { spyOn(advanceRequestService, 'getMyadvanceRequests').and.returnValue(of(teamAdvanceCountRes)); @@ -588,34 +807,6 @@ describe('AdvanceRequestService', () => { }); }); - it('getMyadvanceRequests(): should get all advance request', (done) => { - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); - apiv2Service.get.and.returnValue(of(allAdvanceRequestsRes)); - - const param = { - offset: 0, - limit: 10, - queryParams: { - areq_advance_id: 'is.null', - order: 'areq_created_at.desc,areq_id.desc', - }, - }; - - advanceRequestService.getMyadvanceRequests(param).subscribe((res) => { - expect(res).toEqual(allAdvanceRequestsRes); - expect(apiv2Service.get).toHaveBeenCalledOnceWith('/advance_requests', { - params: { - offset: param.offset, - limit: param.limit, - areq_org_user_id: 'eq.' + apiEouRes.ou.id, - ...param.queryParams, - }, - }); - expect(authService.getEou).toHaveBeenCalledTimes(1); - done(); - }); - }); - describe('getTeamAdvanceRequests():', () => { it('should get all team advance requests | APPROVAL PENDING AND APPROVED', (done) => { authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); diff --git a/src/app/core/services/advance-request.service.ts b/src/app/core/services/advance-request.service.ts index 9295c75253..5660aa4929 100644 --- a/src/app/core/services/advance-request.service.ts +++ b/src/app/core/services/advance-request.service.ts @@ -29,7 +29,12 @@ import { AdvanceRequestFile } from '../models/advance-request-file.model'; import { UnflattenedAdvanceRequest } from '../models/unflattened-advance-request.model'; import { SpenderService } from './platform/v1/spender/spender.service'; import { PlatformApiResponse } from '../models/platform/platform-api-response.model'; +import { AdvanceRequestPlatform } from '../models/platform/advance-request-platform.model'; +import { ExtendedAdvanceRequestPublic } from '../models/extended-advance-request-public.model'; +import { AdvanceRequestState } from '../models/advance-request-state.model'; +import { ApprovalPublic } from '../models/approval-public.model'; import { StatsResponse } from '../models/platform/v1/stats-response.model'; +import { PlatformConfig } from '../models/platform/platform-config.model'; const advanceRequestsCacheBuster$ = new Subject(); @@ -67,6 +72,88 @@ export class AdvanceRequestService { private spenderService: SpenderService ) {} + private getAdvanceRequestState(advanceRequestState: string): string { + if (advanceRequestState === 'SENT_BACK') { + return 'INQUIRY'; + } else if (advanceRequestState === 'PULLED_BACK') { + return 'DRAFT'; + } + + return advanceRequestState; + } + + mapAdvanceRequest(advanceRequestPlatform: AdvanceRequestPlatform): ExtendedAdvanceRequestPublic { + return { + areq_advance_request_number: advanceRequestPlatform.seq_num, + areq_advance_id: advanceRequestPlatform.advance_id, + areq_amount: advanceRequestPlatform.amount, + areq_approved_at: advanceRequestPlatform.last_approved_at, + areq_created_at: advanceRequestPlatform.created_at, + areq_currency: advanceRequestPlatform.currency, + areq_id: advanceRequestPlatform.id, + areq_notes: advanceRequestPlatform.notes, + areq_org_user_id: advanceRequestPlatform.employee_id, + areq_project_id: advanceRequestPlatform.project_id, + areq_purpose: advanceRequestPlatform.purpose, + areq_source: advanceRequestPlatform.source, + areq_state: this.getAdvanceRequestState(advanceRequestPlatform.state), + areq_updated_at: advanceRequestPlatform.updated_at, + ou_department: advanceRequestPlatform.employee.department && advanceRequestPlatform.employee.department.name, + ou_department_id: advanceRequestPlatform.employee.department && advanceRequestPlatform.employee.department.id, + ou_id: advanceRequestPlatform.employee_id, + ou_org_id: advanceRequestPlatform.org_id, + ou_sub_department: + advanceRequestPlatform.employee.department && advanceRequestPlatform.employee.department.sub_department, + us_email: advanceRequestPlatform.user.email, + us_full_name: advanceRequestPlatform.user.full_name, + areq_is_pulled_back: advanceRequestPlatform.state === AdvanceRequestState.PULLED_BACK, + ou_employee_id: advanceRequestPlatform.employee_id, + areq_custom_field_values: advanceRequestPlatform.custom_fields, + areq_is_sent_back: advanceRequestPlatform.state === AdvanceRequestState.SENT_BACK, + project_name: advanceRequestPlatform.project && advanceRequestPlatform.project.name, + project_code: advanceRequestPlatform.project && advanceRequestPlatform.project.code, + }; + } + + convertToPublicAdvanceRequest( + advanceReqPlatformResponse: PlatformApiResponse + ): ExtendedAdvanceRequestPublic[] { + return advanceReqPlatformResponse.data.map((advanceRequestPlatform) => + this.mapAdvanceRequest(advanceRequestPlatform) + ); + } + + @Cacheable({ + cacheBusterObserver: advanceRequestsCacheBuster$, + }) + getSpenderAdvanceRequests( + config: PlatformConfig = { + offset: 0, + limit: 200, + queryParams: {}, + } + ): Observable> { + const params = { + offset: config.offset, + limit: config.limit, + advance_id: 'eq.null', + ...config.queryParams, + }; + return this.spenderService + .get>('/advance_requests', { + params, + }) + .pipe( + map((res) => { + return { + count: res.count, + offset: res.offset, + data: this.convertToPublicAdvanceRequest(res), + }; + }) + ); + } + @Cacheable({ cacheBusterObserver: advanceRequestsCacheBuster$, }) @@ -109,6 +196,21 @@ export class AdvanceRequestService { .pipe(map((res) => this.fixDates(res.data[0]))); } + @Cacheable({ + cacheBusterObserver: advanceRequestsCacheBuster$, + }) + getAdvanceRequestPlatform(id: string): Observable { + return this.spenderService + .get>('/advance_requests', { + params: { id: `eq.${id}` }, + }) + .pipe( + map((res) => { + return this.mapAdvanceRequest(this.fixDatesForPlatformFields(res.data[0])); + }) + ); + } + @CacheBuster({ cacheBusterNotifier: advanceRequestsCacheBuster$, }) @@ -228,7 +330,7 @@ export class AdvanceRequestService { } getEReq(advanceRequestId: string): Observable { - return this.apiService.get('/eadvance_requests/' + advanceRequestId).pipe( + return this.getAdvanceRequestPlatform(advanceRequestId).pipe( map((res) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const eAdvanceRequest: UnflattenedAdvanceRequest = this.dataTransformService.unflatten(res); @@ -255,6 +357,29 @@ export class AdvanceRequestService { ); } + getActiveApproversByAdvanceRequestIdPlatform(advanceRequestId: string): Observable { + return this.spenderService + .get>('/advance_requests', { + params: { id: `eq.${advanceRequestId}` }, + }) + .pipe( + map((res) => { + const approvals = res.data[0].approvals; + const filteredApprovers = []; + approvals.filter((approver) => { + if (approver.state !== 'APPROVAL_DISABLED') { + filteredApprovers.push({ + approver_name: approver.approver_user.full_name, + approver_email: approver.approver_user.email, + state: approver.state, + }); + } + }); + return filteredApprovers; + }) + ); + } + getMyAdvanceRequestsCount(queryParams = {}): Observable { return this.getMyadvanceRequests({ offset: 0, @@ -263,6 +388,14 @@ export class AdvanceRequestService { }).pipe(map((advanceRequest) => advanceRequest.count)); } + getSpenderAdvanceRequestsCount(queryParams = {}): Observable { + return this.getSpenderAdvanceRequests({ + offset: 0, + limit: 1, + queryParams, + }).pipe(map((advanceRequest) => advanceRequest.count)); + } + getTeamAdvanceRequestsCount(queryParams: {}, filter: Filters): Observable { return this.getTeamAdvanceRequests({ offset: 0, @@ -282,7 +415,10 @@ export class AdvanceRequestService { return customFields; } - getInternalStateAndDisplayName(advanceRequest: ExtendedAdvanceRequest): { state: string; name: string } { + getInternalStateAndDisplayName(advanceRequest: ExtendedAdvanceRequest | ExtendedAdvanceRequestPublic): { + state: string; + name: string; + } { let internalRepresentation: { state: string; name: string } = { state: null, name: null, @@ -405,7 +541,7 @@ export class AdvanceRequestService { } private fixDates(data: ExtendedAdvanceRequest): ExtendedAdvanceRequest { - if (data?.areq_created_at) { + if (data && data.areq_created_at) { data.areq_created_at = new Date(data.areq_created_at); } @@ -420,7 +556,23 @@ export class AdvanceRequestService { return data; } - private getStateIfDraft(advanceRequest: ExtendedAdvanceRequest): { + private fixDatesForPlatformFields(data: AdvanceRequestPlatform): AdvanceRequestPlatform { + if (data.created_at) { + data.created_at = new Date(data.created_at); + } + + if (data.updated_at) { + data.updated_at = new Date(data.updated_at); + } + + if (data.last_approved_at) { + data.last_approved_at = new Date(data.last_approved_at); + } + + return data; + } + + private getStateIfDraft(advanceRequest: ExtendedAdvanceRequest | ExtendedAdvanceRequestPublic): { state: string; name: string; } { diff --git a/src/app/core/services/advance.service.spec.ts b/src/app/core/services/advance.service.spec.ts index d596ef8277..9928262776 100644 --- a/src/app/core/services/advance.service.spec.ts +++ b/src/app/core/services/advance.service.spec.ts @@ -1,6 +1,4 @@ import { TestBed } from '@angular/core/testing'; -import { ApiV2Service } from './api-v2.service'; -import { AuthService } from './auth.service'; import { AdvanceService } from './advance.service'; import { singleExtendedAdvancesData, @@ -9,31 +7,26 @@ import { } from '../mock-data/extended-advance.data'; import { apiEouRes } from '../mock-data/extended-org-user.data'; import { of } from 'rxjs'; +import { SpenderService } from './platform/v1/spender/spender.service'; +import { advancePlatform } from '../mock-data/advance-platform.data'; describe('AdvanceService', () => { let advanceService: AdvanceService; - let apiv2Service: jasmine.SpyObj; - let authService: jasmine.SpyObj; + let spenderService: jasmine.SpyObj; beforeEach(() => { - const apiv2ServiceSpy = jasmine.createSpyObj('ApiV2Service', ['get']); - const authServiceSpy = jasmine.createSpyObj('AuthService', ['getEou']); + const spenderServiceSpy = jasmine.createSpyObj('SpenderService', ['get']); TestBed.configureTestingModule({ providers: [ AdvanceService, { - provide: ApiV2Service, - useValue: apiv2ServiceSpy, - }, - { - provide: AuthService, - useValue: authServiceSpy, + provide: SpenderService, + useValue: spenderServiceSpy, }, ], }); advanceService = TestBed.inject(AdvanceService); - apiv2Service = TestBed.inject(ApiV2Service) as jasmine.SpyObj; - authService = TestBed.inject(AuthService) as jasmine.SpyObj; + spenderService = TestBed.inject(SpenderService) as jasmine.SpyObj; }); it('should be created', () => { @@ -42,15 +35,15 @@ describe('AdvanceService', () => { it('getAdvance(): should get an advance from ID', (done) => { const id = 'advETmi3eePvQ'; - apiv2Service.get.and.returnValue(of(singleExtendedAdvancesData)); + spenderService.get.and.returnValue(of(advancePlatform)); // @ts-ignore spyOn(advanceService, 'fixDates').and.returnValue(singleExtendedAdvancesData.data[0]); advanceService.getAdvance(id).subscribe((res) => { expect(res).toEqual(singleExtendedAdvancesData.data[0]); - expect(apiv2Service.get).toHaveBeenCalledOnceWith('/advances', { + expect(spenderService.get).toHaveBeenCalledOnceWith('/advances', { params: { - adv_id: `eq.${id}`, + id: `eq.${id}`, }, }); // @ts-ignore @@ -70,27 +63,22 @@ describe('AdvanceService', () => { expect(advanceService.fixDates(extendedAdvWithoutDates)).toEqual(extendedAdvWithDates); }); - describe('getMyadvances():', () => { + describe('getSpenderAdvances():', () => { it('should return advances', (done) => { const config = { offset: 0, - limit: 10, - queryParams: { status: 'ACTIVE' }, + limit: 200, }; - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); - apiv2Service.get.and.returnValue(of(singleExtendedAdvancesData)); - advanceService.getMyadvances(config).subscribe((res) => { + spenderService.get.and.returnValue(of(advancePlatform)); + advanceService.getSpenderAdvances(config).subscribe((res) => { expect(res).toEqual(singleExtendedAdvancesData); - expect(apiv2Service.get).toHaveBeenCalledWith('/advances', { + expect(spenderService.get).toHaveBeenCalledWith('/advances', { params: { offset: config.offset, limit: config.limit, - assignee_ou_id: 'eq.' + apiEouRes.ou.id, - ...config.queryParams, }, }); - expect(authService.getEou).toHaveBeenCalledTimes(1); }); done(); }); @@ -98,22 +86,18 @@ describe('AdvanceService', () => { it('should return advances without queryparams', (done) => { const config = { offset: 0, - limit: 10, + limit: 200, queryParams: {}, }; - - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); - apiv2Service.get.and.returnValue(of(singleExtendedAdvancesData)); - advanceService.getMyadvances().subscribe((res) => { + spenderService.get.and.returnValue(of(advancePlatform)); + advanceService.getSpenderAdvances().subscribe((res) => { expect(res).toEqual(singleExtendedAdvancesData); - expect(apiv2Service.get).toHaveBeenCalledWith('/advances', { + expect(spenderService.get).toHaveBeenCalledWith('/advances', { params: { offset: config.offset, limit: config.limit, - assignee_ou_id: 'eq.' + apiEouRes.ou.id, }, }); - expect(authService.getEou).toHaveBeenCalledTimes(1); }); done(); }); @@ -121,13 +105,13 @@ describe('AdvanceService', () => { describe('getMyAdvancesCount():', () => { it(' should get advances count', (done) => { - spyOn(advanceService, 'getMyadvances').and.returnValue(of(singleExtendedAdvancesData)); + spyOn(advanceService, 'getSpenderAdvances').and.returnValue(of(singleExtendedAdvancesData)); const queryParams = { status: 'ACTIVE', }; advanceService.getMyAdvancesCount(queryParams).subscribe((res) => { expect(res).toEqual(singleExtendedAdvancesData.count); - expect(advanceService.getMyadvances).toHaveBeenCalledOnceWith({ + expect(advanceService.getSpenderAdvances).toHaveBeenCalledOnceWith({ offset: 0, limit: 1, queryParams: { ...queryParams }, @@ -137,10 +121,10 @@ describe('AdvanceService', () => { }); it(' should get advances count without queryparams', (done) => { - spyOn(advanceService, 'getMyadvances').and.returnValue(of(singleExtendedAdvancesData)); + spyOn(advanceService, 'getSpenderAdvances').and.returnValue(of(singleExtendedAdvancesData)); advanceService.getMyAdvancesCount().subscribe((res) => { expect(res).toEqual(singleExtendedAdvancesData.count); - expect(advanceService.getMyadvances).toHaveBeenCalledOnceWith({ + expect(advanceService.getSpenderAdvances).toHaveBeenCalledOnceWith({ offset: 0, limit: 1, queryParams: {}, diff --git a/src/app/core/services/advance.service.ts b/src/app/core/services/advance.service.ts index d7d36ccc58..7c703f7783 100644 --- a/src/app/core/services/advance.service.ts +++ b/src/app/core/services/advance.service.ts @@ -6,6 +6,10 @@ import { ApiV2Response } from '../models/api-v2.model'; import { ExtendedAdvance } from '../models/extended_advance.model'; import { ApiV2Service } from './api-v2.service'; import { AuthService } from './auth.service'; +import { AdvancesPlatform } from '../models/platform/advances-platform.model'; +import { PlatformApiResponse } from '../models/platform/platform-api-response.model'; +import { SpenderService } from './platform/v1/spender/spender.service'; +import { PlatformConfig } from '../models/platform/platform-config.model'; const advancesCacheBuster$ = new Subject(); @@ -15,42 +19,71 @@ type Config = Partial<{ offset: number; limit: number; assignee_ou_id?: string; providedIn: 'root', }) export class AdvanceService { - constructor(private apiv2Service: ApiV2Service, private authService: AuthService) {} + constructor(private spenderService: SpenderService) {} + mapAdvance(advancesPlatform: AdvancesPlatform): ExtendedAdvance { + return { + adv_advance_number: advancesPlatform.seq_num, + adv_amount: advancesPlatform.amount, + adv_card_number: advancesPlatform.card_number, + adv_created_at: advancesPlatform.created_at, + adv_currency: advancesPlatform.currency, + adv_exported: advancesPlatform.is_exported, + adv_id: advancesPlatform.id, + adv_issued_at: advancesPlatform.issued_at, + adv_mode: advancesPlatform.payment_mode, + adv_orig_amount: advancesPlatform.foreign_amount, + adv_orig_currency: advancesPlatform.foreign_currency, + adv_purpose: advancesPlatform.purpose, + adv_refcode: advancesPlatform.code, + adv_settlement_id: advancesPlatform.settlement_id, + adv_source: advancesPlatform.source, + areq_id: advancesPlatform.advance_request_id, + assignee_department_id: advancesPlatform.employee.department && advancesPlatform.employee.department.id, + assignee_ou_id: advancesPlatform.employee.id, + assignee_ou_org_id: advancesPlatform.employee.org_id, + assignee_us_email: advancesPlatform.employee.user.email, + assignee_us_full_name: advancesPlatform.employee.user.full_name, + project_code: advancesPlatform.project && advancesPlatform.project.code, + project_id: advancesPlatform.project && advancesPlatform.project.id, + project_name: advancesPlatform.project && advancesPlatform.project.name, + type: 'advance', + creator_us_full_name: advancesPlatform.creator_user.full_name, + areq_approved_at: advancesPlatform.advance_request && advancesPlatform.advance_request.last_approved_at, + }; + } + + convertToPublicAdvance(advancesPlatformResponse: PlatformApiResponse): ExtendedAdvance[] { + return advancesPlatformResponse.data.map((advancesPlatform) => this.mapAdvance(advancesPlatform)); + } @Cacheable({ cacheBusterObserver: advancesCacheBuster$, }) - getMyadvances( - config: Config = { + getSpenderAdvances( + config: PlatformConfig = { offset: 0, - limit: 10, + limit: 200, queryParams: {}, } ): Observable> { - return from(this.authService.getEou()).pipe( - switchMap((eou) => - this.apiv2Service.get< - ExtendedAdvance, - { - params: Config; - } - >('/advances', { - params: { - offset: config.offset, - limit: config.limit, - assignee_ou_id: 'eq.' + eou.ou.id, - ...config.queryParams, - }, + const params = { + offset: config.offset, + limit: config.limit, + }; + return this.spenderService + .get>('/advances', { + params, + }) + .pipe( + map((res) => { + return { + count: res.count, + offset: res.offset, + data: this.convertToPublicAdvance(res), + }; }) - ), - map((res) => res as ApiV2Response), - map((res) => ({ - ...res, - data: res.data.map(this.fixDates), - })) - ); + ); } - @CacheBuster({ cacheBusterNotifier: advancesCacheBuster$, }) @@ -59,17 +92,19 @@ export class AdvanceService { } getAdvance(id: string): Observable { - return this.apiv2Service - .get('/advances', { - params: { - adv_id: `eq.${id}`, - }, + return this.spenderService + .get>('/advances', { + params: { id: `eq.${id}` }, }) - .pipe(map((res) => this.fixDates(res.data[0]) as ExtendedAdvance)); + .pipe( + map((res) => { + return this.fixDates(this.mapAdvance(res.data[0])); + }) + ); } getMyAdvancesCount(queryParams = {}) { - return this.getMyadvances({ + return this.getSpenderAdvances({ offset: 0, limit: 1, queryParams, @@ -85,9 +120,6 @@ export class AdvanceService { data.adv_issued_at = new Date(data.adv_issued_at); } - if (data && data.areq_approved_at) { - data.areq_approved_at = new Date(data.areq_approved_at); - } return data; } } diff --git a/src/app/core/services/tasks.service.ts b/src/app/core/services/tasks.service.ts index 194d4ccfe8..c0ea13643b 100644 --- a/src/app/core/services/tasks.service.ts +++ b/src/app/core/services/tasks.service.ts @@ -848,10 +848,6 @@ export class TasksService { return this.getStatsFromResponse(statsResponse, 'count(rp_id)', 'sum(rp_amount)'); } - mapScalarAdvanceStatsResponse(statsResponse: Datum[]): { totalCount: number; totalAmount: number } { - return this.getStatsFromResponse(statsResponse, 'count(areq_id)', 'sum(areq_amount)'); - } - getCommuteDetailsTasks(): Observable { const isCommuteDeductionEnabled$ = this.orgSettingsService .get() diff --git a/src/app/core/services/utility.service.spec.ts b/src/app/core/services/utility.service.spec.ts index 0d601f8932..3900d3fa30 100644 --- a/src/app/core/services/utility.service.spec.ts +++ b/src/app/core/services/utility.service.spec.ts @@ -2,7 +2,11 @@ import { TestBed } from '@angular/core/testing'; import * as dayjs from 'dayjs'; import * as lodash from 'lodash'; import { customFieldData1, customFieldData2 } from '../mock-data/custom-field.data'; -import { allAdvanceRequestsRes, singleExtendedAdvReqRes } from '../mock-data/extended-advance-request.data'; +import { + allAdvanceRequestsRes, + publicAdvanceRequestRes, + singleExtendedAdvReqRes, +} from '../mock-data/extended-advance-request.data'; import { txnDataPayload } from '../mock-data/transaction.data'; import { SortingDirection } from '../models/sorting-direction.model'; import { SortingParam } from '../models/sorting-param.model'; @@ -85,35 +89,35 @@ describe('UtilityService', () => { describe('sortAllAdvances():', () => { it('should sort single advance', () => { - spyOn(lodash, 'cloneDeep').and.returnValue(singleExtendedAdvReqRes.data); - expect(utilityService.sortAllAdvances(0, SortingParam.creationDate, singleExtendedAdvReqRes.data)).toEqual( - singleExtendedAdvReqRes.data + spyOn(lodash, 'cloneDeep').and.returnValue(publicAdvanceRequestRes.data); + expect(utilityService.sortAllAdvances(0, SortingParam.creationDate, publicAdvanceRequestRes.data)).toEqual( + publicAdvanceRequestRes.data ); - expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(singleExtendedAdvReqRes.data); + expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(publicAdvanceRequestRes.data); }); it('should sort multiple advances', () => { - spyOn(lodash, 'cloneDeep').and.returnValue(allAdvanceRequestsRes.data); - expect(utilityService.sortAllAdvances(1, SortingParam.creationDate, allAdvanceRequestsRes.data)).toEqual( - allAdvanceRequestsRes.data + spyOn(lodash, 'cloneDeep').and.returnValue(publicAdvanceRequestRes.data); + expect(utilityService.sortAllAdvances(1, SortingParam.creationDate, publicAdvanceRequestRes.data)).toEqual( + publicAdvanceRequestRes.data ); - expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(allAdvanceRequestsRes.data); + expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(publicAdvanceRequestRes.data); }); it('should sort advances by approval date', () => { - spyOn(lodash, 'cloneDeep').and.returnValue(allAdvanceRequestsRes.data); - expect(utilityService.sortAllAdvances(1, SortingParam.approvalDate, allAdvanceRequestsRes.data)).toEqual( - allAdvanceRequestsRes.data + spyOn(lodash, 'cloneDeep').and.returnValue(publicAdvanceRequestRes.data); + expect(utilityService.sortAllAdvances(1, SortingParam.approvalDate, publicAdvanceRequestRes.data)).toEqual( + publicAdvanceRequestRes.data ); - expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(allAdvanceRequestsRes.data); + expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(publicAdvanceRequestRes.data); }); it('should sort advances by project', () => { - spyOn(lodash, 'cloneDeep').and.returnValue(allAdvanceRequestsRes.data); + spyOn(lodash, 'cloneDeep').and.returnValue(publicAdvanceRequestRes.data); expect( - utilityService.sortAllAdvances(SortingDirection.ascending, SortingParam.project, allAdvanceRequestsRes.data) - ).toEqual(allAdvanceRequestsRes.data); - expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(allAdvanceRequestsRes.data); + utilityService.sortAllAdvances(SortingDirection.ascending, SortingParam.project, publicAdvanceRequestRes.data) + ).toEqual(publicAdvanceRequestRes.data); + expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(publicAdvanceRequestRes.data); }); }); diff --git a/src/app/core/services/utility.service.ts b/src/app/core/services/utility.service.ts index b771fbd5ba..faa123a866 100644 --- a/src/app/core/services/utility.service.ts +++ b/src/app/core/services/utility.service.ts @@ -9,6 +9,7 @@ import { Transaction } from '../models/v1/transaction.model'; import { ExtendedAdvanceRequest } from '../models/extended_advance_request.model'; import { TxnCustomProperties } from '../models/txn-custom-properties.model'; import { OperatorFunction } from 'rxjs'; +import { ExtendedAdvanceRequestPublic } from '../models/extended-advance-request-public.model'; @Injectable({ providedIn: 'root', @@ -124,8 +125,8 @@ export class UtilityService { sortAllAdvances( sortDir: SortingDirection, sortParam: SortingParam, - advancesArray: ExtendedAdvanceRequest[] - ): ExtendedAdvanceRequest[] { + advancesArray: ExtendedAdvanceRequestPublic[] + ): ExtendedAdvanceRequestPublic[] { //used for sorting an array that has both advances and advance requests mixed together const sortedAdvancesArray = cloneDeep(advancesArray); @@ -153,7 +154,7 @@ export class UtilityService { return result; } - private getSortingValue(advance: ExtendedAdvanceRequest, sortParam: SortingParam): dayjs.Dayjs | string { + private getSortingValue(advance: ExtendedAdvanceRequestPublic, sortParam: SortingParam): dayjs.Dayjs | string { if (sortParam === SortingParam.creationDate) { return advance.areq_created_at ? dayjs(advance.areq_created_at) : dayjs(advance.adv_created_at); } else if (sortParam === SortingParam.approvalDate) { diff --git a/src/app/fyle/add-edit-advance-request/add-edit-advance-request-2.page.spec.ts b/src/app/fyle/add-edit-advance-request/add-edit-advance-request-2.page.spec.ts index 26759319b4..c495c260df 100644 --- a/src/app/fyle/add-edit-advance-request/add-edit-advance-request-2.page.spec.ts +++ b/src/app/fyle/add-edit-advance-request/add-edit-advance-request-2.page.spec.ts @@ -11,7 +11,6 @@ import { NetworkService } from 'src/app/core/services/network.service'; import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; import { OrgUserSettingsService } from 'src/app/core/services/org-user-settings.service'; import { ProjectsService } from 'src/app/core/services/projects.service'; -import { StatusService } from 'src/app/core/services/status.service'; import { TrackingService } from 'src/app/core/services/tracking.service'; import { TransactionsOutboxService } from 'src/app/core/services/transactions-outbox.service'; import { AddEditAdvanceRequestPage } from './add-edit-advance-request.page'; @@ -68,7 +67,6 @@ export function TestCases2(getTestBed) { let advanceRequestsCustomFieldsService: jasmine.SpyObj; let advanceRequestService: jasmine.SpyObj; let modalController: jasmine.SpyObj; - let statusService: jasmine.SpyObj; let loaderService: jasmine.SpyObj; let projectsService: jasmine.SpyObj; let popoverController: jasmine.SpyObj; @@ -95,7 +93,6 @@ export function TestCases2(getTestBed) { ) as jasmine.SpyObj; advanceRequestService = TestBed.inject(AdvanceRequestService) as jasmine.SpyObj; modalController = TestBed.inject(ModalController) as jasmine.SpyObj; - statusService = TestBed.inject(StatusService) as jasmine.SpyObj; loaderService = TestBed.inject(LoaderService) as jasmine.SpyObj; projectsService = TestBed.inject(ProjectsService) as jasmine.SpyObj; popoverController = TestBed.inject(PopoverController) as jasmine.SpyObj; diff --git a/src/app/fyle/add-edit-advance-request/add-edit-advance-request.page.ts b/src/app/fyle/add-edit-advance-request/add-edit-advance-request.page.ts index 0b3a486584..cbe45491d7 100644 --- a/src/app/fyle/add-edit-advance-request/add-edit-advance-request.page.ts +++ b/src/app/fyle/add-edit-advance-request/add-edit-advance-request.page.ts @@ -289,14 +289,13 @@ export class AddEditAdvanceRequestPage implements OnInit { } modifyAdvanceRequestCustomFields(customFields: AdvanceRequestCustomFieldValues[]): AdvanceRequestCustomFieldValues[] { - customFields.sort((a, b) => (a.id > b.id ? 1 : -1)); customFields = customFields.map((customField) => { if (customField.type === 'DATE' && customField.value) { const updatedDate = new Date(customField.value.toString()); customField.value = updatedDate.getFullYear() + '-' + (updatedDate.getMonth() + 1) + '-' + updatedDate.getDate(); } - return { id: customField.id, name: customField.name, value: customField.value }; + return { name: customField.name, value: customField.value }; }); this.customFieldValues = customFields; return this.customFieldValues; @@ -577,11 +576,10 @@ export class AddEditAdvanceRequestPage implements OnInit { map((customFields) => { const customFieldsFormArray = this.fg.controls.customFieldValues as FormArray; customFieldsFormArray.clear(); - customFields.sort((a, b) => (a.id > b.id ? 1 : -1)); for (const customField of customFields) { let value; this.customFieldValues.filter((customFieldValue) => { - if (customFieldValue.id === customField.id) { + if (customFieldValue.name === customField.name) { value = customFieldValue.value; } }); diff --git a/src/app/fyle/dashboard/tasks/tasks-2.component.spec.ts b/src/app/fyle/dashboard/tasks/tasks-2.component.spec.ts index 062d629b5b..452d9f79cb 100644 --- a/src/app/fyle/dashboard/tasks/tasks-2.component.spec.ts +++ b/src/app/fyle/dashboard/tasks/tasks-2.component.spec.ts @@ -30,7 +30,7 @@ import { taskCtaData3, taskCtaData9 } from 'src/app/core/mock-data/task-cta.data import { expenseList } from 'src/app/core/mock-data/expense.data'; import { cloneDeep } from 'lodash'; import { apiReportRes } from 'src/app/core/mock-data/api-reports.data'; -import { singleExtendedAdvReqRes } from 'src/app/core/mock-data/extended-advance-request.data'; +import { publicAdvanceRequestRes, singleExtendedAdvReqRes } from 'src/app/core/mock-data/extended-advance-request.data'; import { expensesList, mileageCategoryPlatformExpenseData, @@ -316,7 +316,7 @@ export function TestCases2(getTestBed) { beforeEach(() => { loaderService.showLoader.and.resolveTo(); loaderService.hideLoader.and.resolveTo(); - advanceRequestService.getMyadvanceRequests.and.returnValue(of(singleExtendedAdvReqRes)); + advanceRequestService.getSpenderAdvanceRequests.and.returnValue(of(publicAdvanceRequestRes)); }); it('should get all advances and navigate to add edit advance request page if task count is 1', fakeAsync(() => { @@ -325,10 +325,9 @@ export function TestCases2(getTestBed) { component.onSentBackAdvanceTaskClick(taskCtaData3, mockDashboardTasksData[0]); tick(100); expect(loaderService.showLoader).toHaveBeenCalledOnceWith('Opening your advance request...'); - expect(advanceRequestService.getMyadvanceRequests).toHaveBeenCalledOnceWith({ + expect(advanceRequestService.getSpenderAdvanceRequests).toHaveBeenCalledOnceWith({ queryParams: { - areq_state: 'in.(DRAFT)', - areq_is_sent_back: 'is.true', + state: 'eq.SENT_BACK', }, offset: 0, limit: 1, @@ -338,7 +337,7 @@ export function TestCases2(getTestBed) { '/', 'enterprise', 'add_edit_advance_request', - { id: singleExtendedAdvReqRes.data[0].areq_id }, + { id: publicAdvanceRequestRes.data[0].areq_id }, ]); })); @@ -346,7 +345,7 @@ export function TestCases2(getTestBed) { component.onSentBackAdvanceTaskClick(taskCtaData3, dashboardTasksData[0]); tick(100); expect(loaderService.showLoader).not.toHaveBeenCalled(); - expect(advanceRequestService.getMyadvanceRequests).not.toHaveBeenCalled(); + expect(advanceRequestService.getSpenderAdvanceRequests).not.toHaveBeenCalled(); expect(loaderService.hideLoader).not.toHaveBeenCalled(); expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'my_advances'], { queryParams: { filters: JSON.stringify({ state: ['SENT_BACK'] }) }, diff --git a/src/app/fyle/dashboard/tasks/tasks.component.setup.spec.ts b/src/app/fyle/dashboard/tasks/tasks.component.setup.spec.ts index eb879e0100..e2ed5f8479 100644 --- a/src/app/fyle/dashboard/tasks/tasks.component.setup.spec.ts +++ b/src/app/fyle/dashboard/tasks/tasks.component.setup.spec.ts @@ -46,7 +46,7 @@ describe('TasksComponent', () => { 'addTransactions', 'getAllExtendedReports', ]); - const advanceRequestServiceSpy = jasmine.createSpyObj('AdvanceRequestService', ['getMyadvanceRequests']); + const advanceRequestServiceSpy = jasmine.createSpyObj('AdvanceRequestService', ['getSpenderAdvanceRequests']); const modalControllerSpy = jasmine.createSpyObj('ModalController', ['create']); const trackingServiceSpy = jasmine.createSpyObj('TrackingService', [ 'tasksShown', diff --git a/src/app/fyle/dashboard/tasks/tasks.component.ts b/src/app/fyle/dashboard/tasks/tasks.component.ts index 50db943617..5b0a629877 100644 --- a/src/app/fyle/dashboard/tasks/tasks.component.ts +++ b/src/app/fyle/dashboard/tasks/tasks.component.ts @@ -491,13 +491,12 @@ export class TasksComponent implements OnInit { onSentBackAdvanceTaskClick(taskCta: TaskCta, task: DashboardTask): void { if (task.count === 1) { const queryParams = { - areq_state: 'in.(DRAFT)', - areq_is_sent_back: 'is.true', + state: 'eq.SENT_BACK', }; from(this.loaderService.showLoader('Opening your advance request...')) .pipe( - switchMap(() => this.advanceRequestService.getMyadvanceRequests({ queryParams, offset: 0, limit: 1 })), + switchMap(() => this.advanceRequestService.getSpenderAdvanceRequests({ queryParams, offset: 0, limit: 1 })), finalize(() => this.loaderService.hideLoader()) ) .subscribe((res) => { diff --git a/src/app/fyle/my-advances/my-advances.page.spec.ts b/src/app/fyle/my-advances/my-advances.page.spec.ts index af68f740b5..a62dddf543 100644 --- a/src/app/fyle/my-advances/my-advances.page.spec.ts +++ b/src/app/fyle/my-advances/my-advances.page.spec.ts @@ -18,14 +18,13 @@ import { of } from 'rxjs'; import { transformedResponse2 } from 'src/app/core/mock-data/expense-field.data'; import { allFilterPills } from 'src/app/core/mock-data/filter-pills.data'; import { - allTeamAdvanceRequestsRes, - extendedAdvReqDraft, - extendedAdvReqInquiry, - myAdvanceRequestData5, - myAdvanceRequestsData2, - myAdvanceRequestsData3, - myAdvanceRequestsData4, - singleExtendedAdvReqRes, + publicAdvanceRequestRes, + publicAdvanceRequestRes2, + publicAdvanceRequestRes3, + publicAdvanceRequestRes4, + publicAdvanceRequestRes5, + publicAdvanceRequestRes6, + publicAdvanceRequestResSentBack, } from 'src/app/core/mock-data/extended-advance-request.data'; import { singleExtendedAdvancesData, @@ -62,14 +61,14 @@ describe('MyAdvancesPage', () => { beforeEach(waitForAsync(() => { let advanceRequestServiceSpy = jasmine.createSpyObj('AdvanceRequestService', [ - 'getMyAdvanceRequestsCount', - 'getMyadvanceRequests', + 'getSpenderAdvanceRequestsCount', + 'getSpenderAdvanceRequests', 'destroyAdvanceRequestsCacheBuster', ]); let routerSpy = jasmine.createSpyObj('Router', ['navigate']); let advanceServiceSpy = jasmine.createSpyObj('AdvanceService', [ 'getMyAdvancesCount', - 'getMyadvances', + 'getSpenderAdvances', 'destroyAdvancesCacheBuster', ]); let networkServiceSpy = jasmine.createSpyObj('NetworkService', ['connectivityWatcher', 'isOnline']); @@ -198,18 +197,18 @@ describe('MyAdvancesPage', () => { describe('ionViewWillEnter():', () => { beforeEach(() => { spyOn(component, 'setupNetworkWatcher'); - spyOn(component, 'updateMyAdvanceRequests').and.returnValue(singleExtendedAdvReqRes.data); + spyOn(component, 'updateMyAdvanceRequests').and.returnValue(publicAdvanceRequestRes.data); spyOn(component, 'updateMyAdvances').and.returnValue(singleExtendedAdvancesData.data); spyOn(component, 'getAndUpdateProjectName'); tasksService.getAdvancesTaskCount.and.returnValue(of(4)); tasksService.getTotalTaskCount.and.returnValue(of(5)); filtersHelperService.generateFilterPills.and.returnValue(allFilterPills); - advanceRequestService.getMyAdvanceRequestsCount.and.returnValue(of(1)); - advanceRequestService.getMyadvanceRequests.and.returnValue(of(singleExtendedAdvReqRes)); + advanceRequestService.getSpenderAdvanceRequestsCount.and.returnValue(of(1)); + advanceRequestService.getSpenderAdvanceRequests.and.returnValue(of(publicAdvanceRequestRes)); advanceService.getMyAdvancesCount.and.returnValue(of(1)); - advanceService.getMyadvances.and.returnValue(of(singleExtendedAdvancesData)); + advanceService.getSpenderAdvances.and.returnValue(of(singleExtendedAdvancesData)); orgSettingsService.get.and.returnValue(of(orgSettingsData)); - utilityService.sortAllAdvances.and.returnValue([extendedAdvReqDraft, extendedAdvReqInquiry]); + utilityService.sortAllAdvances.and.returnValue([publicAdvanceRequestRes3, publicAdvanceRequestRes3]); }); it('should call setupNetworkWatcher() once, set advancesTaskCount to 4, navigateBack to true and totalTaskCount to 5', () => { @@ -228,53 +227,53 @@ describe('MyAdvancesPage', () => { expect(filtersHelperService.generateFilterPills).toHaveBeenCalledOnceWith(component.filterParams$.value); }); - it('should set myAdvancerequests$ to singleExtendedAdvReqRes.data', () => { + it('should set myAdvancerequests$ to publicAdvanceRequestRes.data', () => { component.ionViewWillEnter(); component.myAdvanceRequests$.subscribe((res) => { - expect(advanceRequestService.getMyAdvanceRequestsCount).toHaveBeenCalledOnceWith({ - areq_advance_id: 'is.null', + expect(advanceRequestService.getSpenderAdvanceRequestsCount).toHaveBeenCalledOnceWith({ + advance_id: 'eq.null', }); - expect(advanceRequestService.getMyadvanceRequests).toHaveBeenCalledOnceWith({ + expect(advanceRequestService.getSpenderAdvanceRequests).toHaveBeenCalledOnceWith({ offset: 0, - limit: 10, + limit: 200, queryParams: { - areq_advance_id: 'is.null', - order: 'areq_created_at.desc,areq_id.desc', + advance_id: 'eq.null', + order: 'created_at.desc,id.desc', }, }); - expect(res).toEqual(singleExtendedAdvReqRes.data); + expect(res).toEqual(publicAdvanceRequestRes.data); }); }); - it('should set myAdvancerequests$ to allTeamAdvanceRequestsRes.data in form of array in case if count is greater than 10', () => { - advanceRequestService.getMyadvanceRequests.and.returnValues( - of(myAdvanceRequestsData2), - of(allTeamAdvanceRequestsRes) + it('should set myAdvancerequests$ to publicAdvanceRequestRes2.data in form of array in case if count is greater than 200', () => { + advanceRequestService.getSpenderAdvanceRequests.and.returnValues( + of(publicAdvanceRequestRes2), + of(publicAdvanceRequestRes2) ); - advanceRequestService.getMyAdvanceRequestsCount.and.returnValue(of(11)); + advanceRequestService.getSpenderAdvanceRequestsCount.and.returnValue(of(201)); component.ionViewWillEnter(); component.myAdvanceRequests$.subscribe((res) => { - expect(advanceRequestService.getMyAdvanceRequestsCount).toHaveBeenCalledOnceWith({ - areq_advance_id: 'is.null', + expect(advanceRequestService.getSpenderAdvanceRequestsCount).toHaveBeenCalledOnceWith({ + advance_id: 'eq.null', }); - expect(advanceRequestService.getMyadvanceRequests).toHaveBeenCalledTimes(2); - expect(advanceRequestService.getMyadvanceRequests).toHaveBeenCalledWith({ + expect(advanceRequestService.getSpenderAdvanceRequests).toHaveBeenCalledTimes(2); + expect(advanceRequestService.getSpenderAdvanceRequests).toHaveBeenCalledWith({ offset: 0, - limit: 10, + limit: 200, queryParams: { - areq_advance_id: 'is.null', - order: 'areq_created_at.desc,areq_id.desc', + advance_id: 'eq.null', + order: 'created_at.desc,id.desc', }, }); - expect(advanceRequestService.getMyadvanceRequests).toHaveBeenCalledWith({ - offset: 10, - limit: 10, + expect(advanceRequestService.getSpenderAdvanceRequests).toHaveBeenCalledWith({ + offset: 200, + limit: 200, queryParams: { - areq_advance_id: 'is.null', - order: 'areq_created_at.desc,areq_id.desc', + advance_id: 'eq.null', + order: 'created_at.desc,id.desc', }, }); - expect(res).toEqual([...myAdvanceRequestsData2.data, ...allTeamAdvanceRequestsRes.data]); + expect(res).toEqual([...publicAdvanceRequestRes2.data, ...publicAdvanceRequestRes2.data]); }); }); @@ -282,11 +281,11 @@ describe('MyAdvancesPage', () => { component.ionViewWillEnter(); component.myAdvances$.subscribe((res) => { expect(advanceService.getMyAdvancesCount).toHaveBeenCalledTimes(1); - expect(advanceService.getMyadvances).toHaveBeenCalledOnceWith({ + expect(advanceService.getSpenderAdvances).toHaveBeenCalledOnceWith({ offset: 0, - limit: 10, + limit: 200, queryParams: { - order: 'adv_created_at.desc,adv_id.desc', + order: 'created_at.desc,id.desc', }, }); expect(res).toEqual(singleExtendedAdvancesData.data); @@ -294,44 +293,47 @@ describe('MyAdvancesPage', () => { }); it('should set myAdvances$ to allTeamAdvanceRequestsRes.data in form of array in case if count is greater than 10', () => { - advanceService.getMyadvances.and.returnValues(of(singleExtendedAdvancesData2), of(singleExtendedAdvancesData)); - advanceService.getMyAdvancesCount.and.returnValue(of(11)); + advanceService.getSpenderAdvances.and.returnValues( + of(singleExtendedAdvancesData2), + of(singleExtendedAdvancesData) + ); + advanceService.getMyAdvancesCount.and.returnValue(of(201)); component.ionViewWillEnter(); component.myAdvances$.subscribe((res) => { expect(advanceService.getMyAdvancesCount).toHaveBeenCalledTimes(1); - expect(advanceService.getMyadvances).toHaveBeenCalledTimes(2); - expect(advanceService.getMyadvances).toHaveBeenCalledWith({ + expect(advanceService.getSpenderAdvances).toHaveBeenCalledTimes(2); + expect(advanceService.getSpenderAdvances).toHaveBeenCalledWith({ offset: 0, - limit: 10, + limit: 200, queryParams: { - order: 'adv_created_at.desc,adv_id.desc', + order: 'created_at.desc,id.desc', }, }); - expect(advanceService.getMyadvances).toHaveBeenCalledWith({ - offset: 10, - limit: 10, + expect(advanceService.getSpenderAdvances).toHaveBeenCalledWith({ + offset: 200, + limit: 200, queryParams: { - order: 'adv_created_at.desc,adv_id.desc', + order: 'created_at.desc,id.desc', }, }); expect(res).toEqual([...singleExtendedAdvancesData2.data, ...singleExtendedAdvancesData.data]); }); }); - it('should set advances$ equals to array containing extendedAdvReqDraft, extendedAdvReqInquiry', () => { + it('should set advances$ equals to array containing draft and sent back advance requests', () => { activatedRoute.snapshot.queryParams.filters = JSON.stringify(myAdvancesFiltersData2); orgSettingsService.get.and.returnValue(of(orgSettingsRes)); component.ionViewWillEnter(); component.advances$.subscribe((res) => { expect(orgSettingsService.get).toHaveBeenCalledTimes(1); - expect(component.updateMyAdvanceRequests).toHaveBeenCalledOnceWith(singleExtendedAdvReqRes.data); + expect(component.updateMyAdvanceRequests).toHaveBeenCalledOnceWith(publicAdvanceRequestRes.data); expect(component.updateMyAdvances).toHaveBeenCalledOnceWith(singleExtendedAdvancesData.data); expect(utilityService.sortAllAdvances).toHaveBeenCalledOnceWith( SortingDirection.ascending, SortingParam.project, [] ); - expect(res).toEqual([extendedAdvReqDraft, extendedAdvReqInquiry]); + expect(res).toEqual([publicAdvanceRequestRes3, publicAdvanceRequestRes3]); }); }); @@ -350,7 +352,7 @@ describe('MyAdvancesPage', () => { SortingParam.project, [] ); - expect(res).toEqual([extendedAdvReqDraft, extendedAdvReqInquiry]); + expect(res).toEqual([publicAdvanceRequestRes3, publicAdvanceRequestRes3]); }); }); @@ -358,8 +360,8 @@ describe('MyAdvancesPage', () => { activatedRoute.snapshot.queryParams.filters = JSON.stringify(draftSentBackFiltersData); component.updateMyAdvanceRequests = jasmine .createSpy() - .and.returnValue([myAdvanceRequestsData3, myAdvanceRequestsData4]); - utilityService.sortAllAdvances.and.returnValue([myAdvanceRequestsData4, myAdvanceRequestsData3]); + .and.returnValue([publicAdvanceRequestRes4, publicAdvanceRequestRes6]); + utilityService.sortAllAdvances.and.returnValue([publicAdvanceRequestRes4, publicAdvanceRequestRes6]); orgSettingsService.get.and.returnValue( of({ ...orgSettingsRes, advance_requests: { enabled: false }, advances: { enabled: false } }) ); @@ -368,12 +370,10 @@ describe('MyAdvancesPage', () => { expect(orgSettingsService.get).toHaveBeenCalledTimes(1); expect(component.updateMyAdvanceRequests).toHaveBeenCalledOnceWith([]); expect(component.updateMyAdvances).toHaveBeenCalledOnceWith([]); - expect(utilityService.sortAllAdvances).toHaveBeenCalledOnceWith( - SortingDirection.ascending, - SortingParam.project, - [myAdvanceRequestsData4, myAdvanceRequestsData3] - ); - expect(res).toEqual([myAdvanceRequestsData4, myAdvanceRequestsData3]); + expect(utilityService.sortAllAdvances).toHaveBeenCalledWith(SortingDirection.ascending, SortingParam.project, [ + publicAdvanceRequestRes4, + ]); + expect(res).toEqual([publicAdvanceRequestRes4, publicAdvanceRequestRes6]); }); }); }); @@ -385,9 +385,9 @@ describe('MyAdvancesPage', () => { }); it('updateMyAdvanceRequests(): should set type, amount, orig_amount, created_at, currency, orig_currency and purpose in my advances request', () => { - const mockMyAdvanceRequestsData = cloneDeep(singleExtendedAdvReqRes.data); + const mockMyAdvanceRequestsData = cloneDeep(publicAdvanceRequestRes5.data); const expectedMyAdvanceRequest = component.updateMyAdvanceRequests(mockMyAdvanceRequestsData); - expect(expectedMyAdvanceRequest).toEqual([myAdvanceRequestData5]); + expect(expectedMyAdvanceRequest).toEqual([publicAdvanceRequestRes3]); }); describe('doRefresh():', () => { @@ -421,7 +421,7 @@ describe('MyAdvancesPage', () => { '/', 'enterprise', 'my_view_advance_request', - { id: 'advETmi3eePvQ' }, + { id: 'advRhdN9D326Y' }, ]); }); @@ -434,13 +434,13 @@ describe('MyAdvancesPage', () => { '/', 'enterprise', 'my_view_advance_request', - { id: 'areqmq8cmnd5v4' }, + { id: 'areqrttywiidF8' }, ]); }); it('should navigate to my_view_advance', () => { component.onAdvanceClick({ advanceRequest: singleExtendedAdvancesData3, internalState: { state: 'INQUIRY' } }); - expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'my_view_advance', { id: 'advETmi3eePvQ' }]); + expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'my_view_advance', { id: 'advRhdN9D326Y' }]); }); it('should navigate to add_edit_advance_request if advance request is request type and it is in inquiry state', () => { @@ -451,7 +451,7 @@ describe('MyAdvancesPage', () => { '/', 'enterprise', 'add_edit_advance_request', - { id: 'advETmi3eePvQ' }, + { id: 'advRhdN9D326Y' }, ]); }); }); diff --git a/src/app/fyle/my-advances/my-advances.page.ts b/src/app/fyle/my-advances/my-advances.page.ts index f174f39a02..a2b355a540 100644 --- a/src/app/fyle/my-advances/my-advances.page.ts +++ b/src/app/fyle/my-advances/my-advances.page.ts @@ -21,9 +21,9 @@ import { SortingValue } from 'src/app/core/models/sorting-value.model'; import { cloneDeep } from 'lodash'; import { ExpenseFieldsService } from 'src/app/core/services/expense-fields.service'; import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; -import { ExtendedAdvanceRequest } from 'src/app/core/models/extended_advance_request.model'; import { ExtendedAdvance } from 'src/app/core/models/extended_advance.model'; import { MyAdvancesFilters } from 'src/app/core/models/my-advances-filters.model'; +import { ExtendedAdvanceRequestPublic } from 'src/app/core/models/extended-advance-request-public.model'; @Component({ selector: 'app-my-advances', @@ -31,7 +31,7 @@ import { MyAdvancesFilters } from 'src/app/core/models/my-advances-filters.model styleUrls: ['./my-advances.page.scss'], }) export class MyAdvancesPage implements AfterViewChecked { - myAdvanceRequests$: Observable; + myAdvanceRequests$: Observable; myAdvances$: Observable; @@ -45,7 +45,7 @@ export class MyAdvancesPage implements AfterViewChecked { refreshAdvances$: Subject = new Subject(); - advances$: Observable<(ExtendedAdvanceRequest | ExtendedAdvance)[]>; + advances$: Observable<(ExtendedAdvanceRequestPublic | ExtendedAdvance)[]>; isConnected$: Observable; @@ -124,45 +124,45 @@ export class MyAdvancesPage implements AfterViewChecked { this.isLoading = true; this.myAdvanceRequests$ = this.advanceRequestService - .getMyAdvanceRequestsCount({ - areq_advance_id: 'is.null', + .getSpenderAdvanceRequestsCount({ + advance_id: 'eq.null', }) .pipe( concatMap((count) => { - count = count > 10 ? count / 10 : 1; + count = count > 200 ? count / 200 : 1; return range(0, count); }), - concatMap((count) => - this.advanceRequestService.getMyadvanceRequests({ - offset: 10 * count, - limit: 10, + concatMap((count) => { + return this.advanceRequestService.getSpenderAdvanceRequests({ + offset: 200 * count, + limit: 200, queryParams: { - areq_advance_id: 'is.null', - order: 'areq_created_at.desc,areq_id.desc', + advance_id: 'eq.null', + order: 'created_at.desc,id.desc', }, - }) - ), + }); + }), map((res) => res.data), reduce((acc, curr) => acc.concat(curr)) ); this.myAdvances$ = this.advanceService.getMyAdvancesCount().pipe( concatMap((count) => { - count = count > 10 ? count / 10 : 1; + count = count > 200 ? count / 200 : 1; return range(0, count); }), concatMap((count) => - this.advanceService.getMyadvances({ - offset: 10 * count, - limit: 10, - queryParams: { order: 'adv_created_at.desc,adv_id.desc' }, + this.advanceService.getSpenderAdvances({ + offset: 200 * count, + limit: 200, + queryParams: { order: 'created_at.desc,id.desc' }, }) ), map((res) => res.data), reduce((acc, curr) => acc.concat(curr)) ); - const sortResults = map((res: (ExtendedAdvanceRequest | ExtendedAdvance)[]) => + const sortResults = map((res: (ExtendedAdvanceRequestPublic | ExtendedAdvance)[]) => res.sort((a, b) => (a.created_at < b.created_at ? 1 : -1)) ); this.advances$ = this.refreshAdvances$.pipe( @@ -184,7 +184,7 @@ export class MyAdvancesPage implements AfterViewChecked { sortResults ) ), - switchMap((advArray: ExtendedAdvanceRequest[]) => + switchMap((advArray: ExtendedAdvanceRequestPublic[]) => //piping through filterParams so that filtering and sorting happens whenever we call next() on filterParams this.filterParams$.pipe( map((filters) => { @@ -194,8 +194,7 @@ export class MyAdvancesPage implements AfterViewChecked { newArr = advArray.filter((adv) => { const sentBackAdvance = filters.state.includes(AdvancesStates.sentBack) && - adv.areq_state === 'DRAFT' && - adv.areq_is_sent_back; + ((adv.areq_state === 'DRAFT' && adv.areq_is_sent_back) || adv.areq_state === 'INQUIRY'); const plainDraft = filters.state.includes(AdvancesStates.draft) && @@ -239,7 +238,7 @@ export class MyAdvancesPage implements AfterViewChecked { return myAdvances; } - updateMyAdvanceRequests(myAdvanceRequests: ExtendedAdvanceRequest[]): ExtendedAdvanceRequest[] { + updateMyAdvanceRequests(myAdvanceRequests: ExtendedAdvanceRequestPublic[]): ExtendedAdvanceRequestPublic[] { myAdvanceRequests = myAdvanceRequests.map((data) => ({ ...data, type: 'request', diff --git a/src/app/fyle/my-view-advance-request/my-view-advance-request.page.spec.ts b/src/app/fyle/my-view-advance-request/my-view-advance-request.page.spec.ts index a55098f9ff..39eb05ef4c 100644 --- a/src/app/fyle/my-view-advance-request/my-view-advance-request.page.spec.ts +++ b/src/app/fyle/my-view-advance-request/my-view-advance-request.page.spec.ts @@ -23,9 +23,9 @@ import { } from 'src/app/core/mock-data/file-object.data'; import { of } from 'rxjs'; import { transformedResponse2 } from 'src/app/core/mock-data/expense-field.data'; -import { extendedAdvReqDraft } from 'src/app/core/mock-data/extended-advance-request.data'; +import { publicAdvanceRequestRes } from 'src/app/core/mock-data/extended-advance-request.data'; import { apiAdvanceRequestAction } from 'src/app/core/mock-data/advance-request-actions.data'; -import { advanceReqApprovals } from 'src/app/core/mock-data/approval.data'; +import { advanceReqApprovals, advanceReqApprovalsPublic } from 'src/app/core/mock-data/approval.data'; import { advanceRequestCustomFieldData2 } from 'src/app/core/mock-data/advance-requests-custom-fields.data'; import { customFields } from 'src/app/core/mock-data/custom-field.data'; import { advanceRequests } from 'src/app/core/mock-data/advance-requests.data'; @@ -50,10 +50,10 @@ describe('MyViewAdvanceRequestPage', () => { beforeEach(waitForAsync(() => { const advanceRequestServiceSpy = jasmine.createSpyObj('AdvanceRequestService', [ - 'getAdvanceRequest', + 'getAdvanceRequestPlatform', 'getActions', 'getInternalStateAndDisplayName', - 'getActiveApproversByAdvanceRequestId', + 'getActiveApproversByAdvanceRequestIdPlatform', 'modifyAdvanceRequestCustomFields', 'pullBackAdvanceRequest', 'delete', @@ -175,13 +175,13 @@ describe('MyViewAdvanceRequestPage', () => { beforeEach(() => { loaderService.showLoader.and.resolveTo(); loaderService.hideLoader.and.resolveTo(); - advanceRequestService.getAdvanceRequest.and.returnValue(of(extendedAdvReqDraft)); + advanceRequestService.getAdvanceRequestPlatform.and.returnValue(of(publicAdvanceRequestRes.data[0])); advanceRequestService.getInternalStateAndDisplayName.and.returnValue({ state: 'DRAFT', name: 'Draft', }); advanceRequestService.getActions.and.returnValue(of(apiAdvanceRequestAction)); - advanceRequestService.getActiveApproversByAdvanceRequestId.and.returnValue(of(advanceReqApprovals)); + advanceRequestService.getActiveApproversByAdvanceRequestIdPlatform.and.returnValue(of(advanceReqApprovalsPublic)); const mockFileObject = cloneDeep(advanceRequestFileUrlData[0]); spyOn(component, 'getReceiptDetails').and.returnValue({ type: 'pdf', @@ -200,12 +200,14 @@ describe('MyViewAdvanceRequestPage', () => { tick(100); component.advanceRequest$.subscribe((res) => { - expect(advanceRequestService.getAdvanceRequest).toHaveBeenCalledOnceWith('areqR1cyLgXdND'); + expect(advanceRequestService.getAdvanceRequestPlatform).toHaveBeenCalledOnceWith('areqR1cyLgXdND'); expect(loaderService.showLoader).toHaveBeenCalledTimes(1); expect(loaderService.hideLoader).toHaveBeenCalledTimes(1); - expect(res).toEqual(extendedAdvReqDraft); + expect(res).toEqual(publicAdvanceRequestRes.data[0]); }); - expect(advanceRequestService.getInternalStateAndDisplayName).toHaveBeenCalledOnceWith(extendedAdvReqDraft); + expect(advanceRequestService.getInternalStateAndDisplayName).toHaveBeenCalledOnceWith( + publicAdvanceRequestRes.data[0] + ); expect(component.internalState).toEqual({ state: 'DRAFT', name: 'Draft', @@ -214,7 +216,7 @@ describe('MyViewAdvanceRequestPage', () => { })); it('should set currency symbol to undefined if advance request is undefined', fakeAsync(() => { - advanceRequestService.getAdvanceRequest.and.returnValue(of(undefined)); + advanceRequestService.getAdvanceRequestPlatform.and.returnValue(of(undefined)); component.ionViewWillEnter(); tick(100); @@ -240,9 +242,11 @@ describe('MyViewAdvanceRequestPage', () => { tick(100); component.activeApprovals$.subscribe((res) => { - expect(res).toEqual(advanceReqApprovals); + expect(res).toEqual(advanceReqApprovalsPublic); }); - expect(advanceRequestService.getActiveApproversByAdvanceRequestId).toHaveBeenCalledOnceWith('areqR1cyLgXdND'); + expect(advanceRequestService.getActiveApproversByAdvanceRequestIdPlatform).toHaveBeenCalledOnceWith( + 'areqR1cyLgXdND' + ); })); it('should set attachedFiles$ to attached files', fakeAsync(() => { @@ -263,11 +267,12 @@ describe('MyViewAdvanceRequestPage', () => { advanceRequestsCustomFieldsService.getAll.and.returnValue(of(mockAdvRequestCustomFields)); component.ionViewWillEnter(); + tick(100); component.advanceRequestCustomFields$.subscribe(() => { expect(advanceRequestService.modifyAdvanceRequestCustomFields).toHaveBeenCalledOnceWith( - JSON.parse(extendedAdvReqDraft.areq_custom_field_values) + publicAdvanceRequestRes.data[0].areq_custom_field_values ); expect(advanceRequestsCustomFieldsService.getAll).toHaveBeenCalledTimes(1); }); @@ -323,7 +328,7 @@ describe('MyViewAdvanceRequestPage', () => { describe('openCommentsModal():', () => { let commentsModalSpy: jasmine.SpyObj; beforeEach(() => { - component.advanceRequest$ = of(extendedAdvReqDraft); + component.advanceRequest$ = of(publicAdvanceRequestRes.data[0]); modalProperties.getModalDefaultProperties.and.returnValue(properties); commentsModalSpy = jasmine.createSpyObj('modal', ['present', 'onDidDismiss']); commentsModalSpy.onDidDismiss.and.resolveTo({ data: { updated: true } }); diff --git a/src/app/fyle/my-view-advance-request/my-view-advance-request.page.ts b/src/app/fyle/my-view-advance-request/my-view-advance-request.page.ts index 0d4bb4d649..780348aeac 100644 --- a/src/app/fyle/my-view-advance-request/my-view-advance-request.page.ts +++ b/src/app/fyle/my-view-advance-request/my-view-advance-request.page.ts @@ -3,9 +3,7 @@ import { ActivatedRoute, Router } from '@angular/router'; import { PopoverController, ModalController } from '@ionic/angular'; import { forkJoin, from, Observable } from 'rxjs'; import { concatMap, finalize, map, reduce, shareReplay, switchMap } from 'rxjs/operators'; -import { Approval } from 'src/app/core/models/approval.model'; import { CustomField } from 'src/app/core/models/custom_field.model'; -import { ExtendedAdvanceRequest } from 'src/app/core/models/extended_advance_request.model'; import { File } from 'src/app/core/models/file.model'; import { AdvanceRequestService } from 'src/app/core/services/advance-request.service'; import { FileService } from 'src/app/core/services/file.service'; @@ -21,6 +19,8 @@ import { FyPopoverComponent } from 'src/app/shared/components/fy-popover/fy-popo import { StatisticTypes } from 'src/app/shared/components/fy-statistic/statistic-type.enum'; import { getCurrencySymbol } from '@angular/common'; import { ExpenseFieldsService } from 'src/app/core/services/expense-fields.service'; +import { ExtendedAdvanceRequestPublic } from 'src/app/core/models/extended-advance-request-public.model'; +import { ApprovalPublic } from 'src/app/core/models/approval-public.model'; @Component({ selector: 'app-my-view-advance-request', @@ -28,11 +28,11 @@ import { ExpenseFieldsService } from 'src/app/core/services/expense-fields.servi styleUrls: ['./my-view-advance-request.page.scss'], }) export class MyViewAdvanceRequestPage implements OnInit { - advanceRequest$: Observable; + advanceRequest$: Observable; actions$: Observable; - activeApprovals$: Observable; + activeApprovals$: Observable; attachedFiles$: Observable; @@ -114,7 +114,7 @@ export class MyViewAdvanceRequestPage implements OnInit { ionViewWillEnter() { const id = this.activatedRoute.snapshot.params.id; this.advanceRequest$ = from(this.loaderService.showLoader()).pipe( - switchMap(() => this.advanceRequestService.getAdvanceRequest(id)), + switchMap(() => this.advanceRequestService.getAdvanceRequestPlatform(id)), finalize(() => from(this.loaderService.hideLoader())), shareReplay(1) ); @@ -125,7 +125,7 @@ export class MyViewAdvanceRequestPage implements OnInit { }); this.actions$ = this.advanceRequestService.getActions(id).pipe(shareReplay(1)); - this.activeApprovals$ = this.advanceRequestService.getActiveApproversByAdvanceRequestId(id); + this.activeApprovals$ = this.advanceRequestService.getActiveApproversByAdvanceRequestIdPlatform(id); this.attachedFiles$ = this.fileService.findByAdvanceRequestId(id).pipe( switchMap((res) => from(res)), concatMap((fileObj: any) => @@ -155,13 +155,13 @@ export class MyViewAdvanceRequestPage implements OnInit { res.advanceRequest.areq_custom_field_values.length > 0 ) { customFieldValues = this.advanceRequestService.modifyAdvanceRequestCustomFields( - JSON.parse(res.advanceRequest.areq_custom_field_values) + res.advanceRequest.areq_custom_field_values ); } res.customFields.map((customField) => { customFieldValues.filter((customFieldValue) => { - if (customField.id === customFieldValue.id) { + if (customField.name === customFieldValue.name) { customField.value = customFieldValue.value; } });