From 648d20e6807fe298946ac16d5af68d2b9927b029 Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Thu, 18 Apr 2024 10:07:14 +0530 Subject: [PATCH] Revert "feat: Move advance req get to platform API (#2854)" (#2871) This reverts commit de91efac7b80018ef2a1469e6961cb8bbf7a0ffa. --- .../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, 435 insertions(+), 1326 deletions(-) delete mode 100644 src/app/core/mock-data/advance-platform.data.ts delete mode 100644 src/app/core/mock-data/platform/v1/advance-request-platform.data.ts delete mode 100644 src/app/core/models/advance-request-state.model.ts delete mode 100644 src/app/core/models/approval-public.model.ts delete mode 100644 src/app/core/models/extended-advance-request-public.model.ts delete mode 100644 src/app/core/models/platform/advance-request-platform.model.ts delete mode 100644 src/app/core/models/platform/advances-platform.model.ts delete mode 100644 src/app/core/models/platform/platform-approval.model.ts delete mode 100644 src/app/core/models/platform/platform-config.model.ts delete mode 100644 src/app/core/models/platform/platform-employee.model.ts delete 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 deleted file mode 100644 index 886398bd3c..0000000000 --- a/src/app/core/mock-data/advance-platform.data.ts +++ /dev/null @@ -1,88 +0,0 @@ -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 497a2a1cbc..5f117f659d 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,42 +2,39 @@ 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: '2023-1-2', + value: '2 Jan 2023', type: 'DATE', }, - { - name: 'Checking', - value: 'option1', - type: 'OPTION', - }, ]; export const advanceRequestCustomFieldValuesData2: AdvanceRequestCustomFieldValues[] = [ { + id: 1302, name: 'Phase', value: 'Phase 1', }, { - name: 'BILLABLE', - value: true, - }, - { + id: 1304, name: 'Arrival Date', value: '2023-1-2', }, { - name: 'Checking', - value: 'option1', + id: 1305, + name: 'BILLABLE', + value: true, }, ]; diff --git a/src/app/core/mock-data/approval.data.ts b/src/app/core/mock-data/approval.data.ts index 64681f81f1..8af90dab47 100644 --- a/src/app/core/mock-data/approval.data.ts +++ b/src/app/core/mock-data/approval.data.ts @@ -1,4 +1,3 @@ -import { ApprovalPublic } from '../models/approval-public.model'; import { Approval } from '../models/approval.model'; export const advanceReqApprovals: Approval[] = [ @@ -17,11 +16,3 @@ 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 ec6281ac0b..a88c58bd16 100644 --- a/src/app/core/mock-data/extended-advance-request.data.ts +++ b/src/app/core/mock-data/extended-advance-request.data.ts @@ -1,6 +1,4 @@ -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 = { @@ -249,40 +247,51 @@ export const withoutDatesAdv = { us_full_name: 'Abhishek Jain', }; -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'), +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', 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', + 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', }; export const singleErqUnflattened = { @@ -552,145 +561,6 @@ 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 b2d3644bc2..9b108ebef8 100644 --- a/src/app/core/mock-data/extended-advance.data.ts +++ b/src/app/core/mock-data/extended-advance.data.ts @@ -1,61 +1,86 @@ 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: [ { - adv_advance_number: 'A/2024/03/T/1', - adv_amount: 5044, + 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, - adv_created_at: new Date('2024-03-11T08:32:40.861Z'), + adv_created_at: new Date('2019-10-31T04:36:01.927Z'), adv_currency: 'INR', adv_exported: false, - adv_id: 'advRhdN9D326Y', - adv_issued_at: new Date('2024-03-11T08:32:27.449Z'), - adv_mode: 'CASH', + adv_id: 'advETmi3eePvQ', + adv_issued_at: new Date('2019-10-31T04:35:10.391Z'), + adv_mode: 'BANK_TRANSFER', adv_orig_amount: null, adv_orig_currency: null, - adv_purpose: 'testing', + adv_payment_id: 'payoMxfqFQXCO', + adv_purpose: 'New advance-2', adv_refcode: null, - adv_settlement_id: null, + adv_settlement_id: 'setc2r9i3I2xr', adv_source: 'WEBAPP', - areq_id: 'areqrttywiidF8', - assignee_department_id: 'dept62zPkMskdX', - assignee_ou_id: 'ouX8dwsbLCLv', + 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: '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'), + 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, }, ], + 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, @@ -67,21 +92,34 @@ 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, @@ -92,86 +130,10 @@ export const singleExtendedAdvancesData2: ApiV2Response = { export const singleExtendedAdvancesData3: ExtendedAdvance = { ...singleExtendedAdvancesData.data[0], type: 'advance', - amount: 5044, + amount: 300, orig_amount: null, - created_at: new Date('2024-03-11T08:32:40.861Z'), + created_at: new Date('2019-10-31T04:36:01.927Z'), currency: 'INR', orig_currency: null, - 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', - }, - ], + purpose: 'New advance-2', }; diff --git a/src/app/core/mock-data/modal-controller.data.ts b/src/app/core/mock-data/modal-controller.data.ts index e165cfea06..f404ca377d 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: 'areqiwr3Wwirr', + objectId: 'areqoVuT5I8OOy', }, 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 deleted file mode 100644 index 2d8a713e27..0000000000 --- a/src/app/core/mock-data/platform/v1/advance-request-platform.data.ts +++ /dev/null @@ -1,114 +0,0 @@ -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 0495023096..07f9451de4 100644 --- a/src/app/core/mock-data/stats-dimension-response.data.ts +++ b/src/app/core/mock-data/stats-dimension-response.data.ts @@ -1,4 +1,3 @@ -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 5a40adfad3..0d122dcef0 100644 --- a/src/app/core/mock-data/unflattened-advance-request.data.ts +++ b/src/app/core/mock-data/unflattened-advance-request.data.ts @@ -18,11 +18,13 @@ 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 deleted file mode 100644 index 5d43cdab40..0000000000 --- a/src/app/core/models/advance-request-state.model.ts +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 28957f5097..0000000000 --- a/src/app/core/models/approval-public.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index a0dfe950e6..0000000000 --- a/src/app/core/models/extended-advance-request-public.model.ts +++ /dev/null @@ -1,42 +0,0 @@ -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 896b050657..650e827dba 100644 --- a/src/app/core/models/extended_advance.model.ts +++ b/src/app/core/models/extended_advance.model.ts @@ -1,37 +1,54 @@ -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: boolean; + adv_exported: false; 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; - orig_currency?: string; purpose?: string; - creator_us_full_name: string; - areq_approved_at: Date; + orig_currency?: string; + created_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 deleted file mode 100644 index 4baf9744e9..0000000000 --- a/src/app/core/models/platform/advance-request-platform.model.ts +++ /dev/null @@ -1,37 +0,0 @@ -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 deleted file mode 100644 index fa2c49ff10..0000000000 --- a/src/app/core/models/platform/advances-platform.model.ts +++ /dev/null @@ -1,44 +0,0 @@ -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 d61e23fd36..2485327354 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 deleted file mode 100644 index 9fd239308c..0000000000 --- a/src/app/core/models/platform/platform-approval.model.ts +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index d31684ff1d..0000000000 --- a/src/app/core/models/platform/platform-config.model.ts +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index cbf8b77956..0000000000 --- a/src/app/core/models/platform/platform-employee.model.ts +++ /dev/null @@ -1,12 +0,0 @@ -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 3b9743108e..648a30d9b4 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 deleted file mode 100644 index b7efabc445..0000000000 --- a/src/app/core/models/platform/v1/platform-advance.model.ts +++ /dev/null @@ -1,7 +0,0 @@ -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 8787ea8cc1..75b05fb3a8 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 fc58d6bdd3..b88e2dcab7 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, advanceReqApprovalsPublic } from '../mock-data/approval.data'; +import { advanceReqApprovals } from '../mock-data/approval.data'; import { customField2, customFields, @@ -32,9 +32,6 @@ import { extendedAdvReqSubmitted, extendedAdvReqWithDates, extendedAdvReqWithoutDates, - publicAdvanceRequestRes, - publicAdvanceRequestResPulledBack, - publicAdvanceRequestResSentBack, singleErqRes, singleErqUnflattened, singleExtendedAdvReqRes, @@ -56,12 +53,6 @@ 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; @@ -83,7 +74,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', 'get']); + const spenderServiceSpy = jasmine.createSpyObj('SpenderService', ['post']); TestBed.configureTestingModule({ providers: [ @@ -165,74 +156,6 @@ 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)); @@ -331,6 +254,7 @@ describe('AdvanceRequestService', () => { const params = { state: 'eq.SENT_BACK', }; + advanceRequestService.getAdvanceRequestStats(params).subscribe((res) => { expect(res).toEqual(statsResponse); expect(spenderService.post).toHaveBeenCalledOnceWith('/advance_requests/stats', { @@ -463,13 +387,6 @@ 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 @@ -483,20 +400,6 @@ 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'; @@ -558,7 +461,7 @@ describe('AdvanceRequestService', () => { }); it('getEReq(): should get advance request', (done) => { - spyOn(advanceRequestService, 'getAdvanceRequestPlatform').and.returnValue(of(publicAdvanceRequestRes.data[0])); + apiService.get.and.returnValue(of(singleErqRes)); dataTransformService.unflatten.and.returnValue(singleErqUnflattened); spyOn(dateService, 'fixDates').and.returnValue(of(expectedSingleErq)); @@ -652,128 +555,6 @@ 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)); @@ -807,6 +588,34 @@ 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 5660aa4929..9295c75253 100644 --- a/src/app/core/services/advance-request.service.ts +++ b/src/app/core/services/advance-request.service.ts @@ -29,12 +29,7 @@ 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(); @@ -72,88 +67,6 @@ 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$, }) @@ -196,21 +109,6 @@ 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$, }) @@ -330,7 +228,7 @@ export class AdvanceRequestService { } getEReq(advanceRequestId: string): Observable { - return this.getAdvanceRequestPlatform(advanceRequestId).pipe( + return this.apiService.get('/eadvance_requests/' + advanceRequestId).pipe( map((res) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const eAdvanceRequest: UnflattenedAdvanceRequest = this.dataTransformService.unflatten(res); @@ -357,29 +255,6 @@ 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, @@ -388,14 +263,6 @@ 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, @@ -415,10 +282,7 @@ export class AdvanceRequestService { return customFields; } - getInternalStateAndDisplayName(advanceRequest: ExtendedAdvanceRequest | ExtendedAdvanceRequestPublic): { - state: string; - name: string; - } { + getInternalStateAndDisplayName(advanceRequest: ExtendedAdvanceRequest): { state: string; name: string } { let internalRepresentation: { state: string; name: string } = { state: null, name: null, @@ -541,7 +405,7 @@ export class AdvanceRequestService { } private fixDates(data: ExtendedAdvanceRequest): ExtendedAdvanceRequest { - if (data && data.areq_created_at) { + if (data?.areq_created_at) { data.areq_created_at = new Date(data.areq_created_at); } @@ -556,23 +420,7 @@ export class AdvanceRequestService { return data; } - 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): { + private getStateIfDraft(advanceRequest: ExtendedAdvanceRequest): { 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 9928262776..d596ef8277 100644 --- a/src/app/core/services/advance.service.spec.ts +++ b/src/app/core/services/advance.service.spec.ts @@ -1,4 +1,6 @@ import { TestBed } from '@angular/core/testing'; +import { ApiV2Service } from './api-v2.service'; +import { AuthService } from './auth.service'; import { AdvanceService } from './advance.service'; import { singleExtendedAdvancesData, @@ -7,26 +9,31 @@ 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 spenderService: jasmine.SpyObj; + let apiv2Service: jasmine.SpyObj; + let authService: jasmine.SpyObj; beforeEach(() => { - const spenderServiceSpy = jasmine.createSpyObj('SpenderService', ['get']); + const apiv2ServiceSpy = jasmine.createSpyObj('ApiV2Service', ['get']); + const authServiceSpy = jasmine.createSpyObj('AuthService', ['getEou']); TestBed.configureTestingModule({ providers: [ AdvanceService, { - provide: SpenderService, - useValue: spenderServiceSpy, + provide: ApiV2Service, + useValue: apiv2ServiceSpy, + }, + { + provide: AuthService, + useValue: authServiceSpy, }, ], }); advanceService = TestBed.inject(AdvanceService); - spenderService = TestBed.inject(SpenderService) as jasmine.SpyObj; + apiv2Service = TestBed.inject(ApiV2Service) as jasmine.SpyObj; + authService = TestBed.inject(AuthService) as jasmine.SpyObj; }); it('should be created', () => { @@ -35,15 +42,15 @@ describe('AdvanceService', () => { it('getAdvance(): should get an advance from ID', (done) => { const id = 'advETmi3eePvQ'; - spenderService.get.and.returnValue(of(advancePlatform)); + apiv2Service.get.and.returnValue(of(singleExtendedAdvancesData)); // @ts-ignore spyOn(advanceService, 'fixDates').and.returnValue(singleExtendedAdvancesData.data[0]); advanceService.getAdvance(id).subscribe((res) => { expect(res).toEqual(singleExtendedAdvancesData.data[0]); - expect(spenderService.get).toHaveBeenCalledOnceWith('/advances', { + expect(apiv2Service.get).toHaveBeenCalledOnceWith('/advances', { params: { - id: `eq.${id}`, + adv_id: `eq.${id}`, }, }); // @ts-ignore @@ -63,22 +70,27 @@ describe('AdvanceService', () => { expect(advanceService.fixDates(extendedAdvWithoutDates)).toEqual(extendedAdvWithDates); }); - describe('getSpenderAdvances():', () => { + describe('getMyadvances():', () => { it('should return advances', (done) => { const config = { offset: 0, - limit: 200, + limit: 10, + queryParams: { status: 'ACTIVE' }, }; - spenderService.get.and.returnValue(of(advancePlatform)); - advanceService.getSpenderAdvances(config).subscribe((res) => { + authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); + apiv2Service.get.and.returnValue(of(singleExtendedAdvancesData)); + advanceService.getMyadvances(config).subscribe((res) => { expect(res).toEqual(singleExtendedAdvancesData); - expect(spenderService.get).toHaveBeenCalledWith('/advances', { + expect(apiv2Service.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(); }); @@ -86,18 +98,22 @@ describe('AdvanceService', () => { it('should return advances without queryparams', (done) => { const config = { offset: 0, - limit: 200, + limit: 10, queryParams: {}, }; - spenderService.get.and.returnValue(of(advancePlatform)); - advanceService.getSpenderAdvances().subscribe((res) => { + + authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); + apiv2Service.get.and.returnValue(of(singleExtendedAdvancesData)); + advanceService.getMyadvances().subscribe((res) => { expect(res).toEqual(singleExtendedAdvancesData); - expect(spenderService.get).toHaveBeenCalledWith('/advances', { + expect(apiv2Service.get).toHaveBeenCalledWith('/advances', { params: { offset: config.offset, limit: config.limit, + assignee_ou_id: 'eq.' + apiEouRes.ou.id, }, }); + expect(authService.getEou).toHaveBeenCalledTimes(1); }); done(); }); @@ -105,13 +121,13 @@ describe('AdvanceService', () => { describe('getMyAdvancesCount():', () => { it(' should get advances count', (done) => { - spyOn(advanceService, 'getSpenderAdvances').and.returnValue(of(singleExtendedAdvancesData)); + spyOn(advanceService, 'getMyadvances').and.returnValue(of(singleExtendedAdvancesData)); const queryParams = { status: 'ACTIVE', }; advanceService.getMyAdvancesCount(queryParams).subscribe((res) => { expect(res).toEqual(singleExtendedAdvancesData.count); - expect(advanceService.getSpenderAdvances).toHaveBeenCalledOnceWith({ + expect(advanceService.getMyadvances).toHaveBeenCalledOnceWith({ offset: 0, limit: 1, queryParams: { ...queryParams }, @@ -121,10 +137,10 @@ describe('AdvanceService', () => { }); it(' should get advances count without queryparams', (done) => { - spyOn(advanceService, 'getSpenderAdvances').and.returnValue(of(singleExtendedAdvancesData)); + spyOn(advanceService, 'getMyadvances').and.returnValue(of(singleExtendedAdvancesData)); advanceService.getMyAdvancesCount().subscribe((res) => { expect(res).toEqual(singleExtendedAdvancesData.count); - expect(advanceService.getSpenderAdvances).toHaveBeenCalledOnceWith({ + expect(advanceService.getMyadvances).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 7c703f7783..d7d36ccc58 100644 --- a/src/app/core/services/advance.service.ts +++ b/src/app/core/services/advance.service.ts @@ -6,10 +6,6 @@ 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(); @@ -19,71 +15,42 @@ type Config = Partial<{ offset: number; limit: number; assignee_ou_id?: string; providedIn: 'root', }) export class AdvanceService { - constructor(private spenderService: SpenderService) {} + constructor(private apiv2Service: ApiV2Service, private authService: AuthService) {} - 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$, }) - getSpenderAdvances( - config: PlatformConfig = { + getMyadvances( + config: Config = { offset: 0, - limit: 200, + limit: 10, queryParams: {}, } ): Observable> { - 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), - }; + 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, + }, }) - ); + ), + map((res) => res as ApiV2Response), + map((res) => ({ + ...res, + data: res.data.map(this.fixDates), + })) + ); } + @CacheBuster({ cacheBusterNotifier: advancesCacheBuster$, }) @@ -92,19 +59,17 @@ export class AdvanceService { } getAdvance(id: string): Observable { - return this.spenderService - .get>('/advances', { - params: { id: `eq.${id}` }, + return this.apiv2Service + .get('/advances', { + params: { + adv_id: `eq.${id}`, + }, }) - .pipe( - map((res) => { - return this.fixDates(this.mapAdvance(res.data[0])); - }) - ); + .pipe(map((res) => this.fixDates(res.data[0]) as ExtendedAdvance)); } getMyAdvancesCount(queryParams = {}) { - return this.getSpenderAdvances({ + return this.getMyadvances({ offset: 0, limit: 1, queryParams, @@ -120,6 +85,9 @@ 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 c0ea13643b..194d4ccfe8 100644 --- a/src/app/core/services/tasks.service.ts +++ b/src/app/core/services/tasks.service.ts @@ -848,6 +848,10 @@ 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 3900d3fa30..0d601f8932 100644 --- a/src/app/core/services/utility.service.spec.ts +++ b/src/app/core/services/utility.service.spec.ts @@ -2,11 +2,7 @@ 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, - publicAdvanceRequestRes, - singleExtendedAdvReqRes, -} from '../mock-data/extended-advance-request.data'; +import { allAdvanceRequestsRes, 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'; @@ -89,35 +85,35 @@ describe('UtilityService', () => { describe('sortAllAdvances():', () => { it('should sort single advance', () => { - spyOn(lodash, 'cloneDeep').and.returnValue(publicAdvanceRequestRes.data); - expect(utilityService.sortAllAdvances(0, SortingParam.creationDate, publicAdvanceRequestRes.data)).toEqual( - publicAdvanceRequestRes.data + spyOn(lodash, 'cloneDeep').and.returnValue(singleExtendedAdvReqRes.data); + expect(utilityService.sortAllAdvances(0, SortingParam.creationDate, singleExtendedAdvReqRes.data)).toEqual( + singleExtendedAdvReqRes.data ); - expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(publicAdvanceRequestRes.data); + expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(singleExtendedAdvReqRes.data); }); it('should sort multiple advances', () => { - spyOn(lodash, 'cloneDeep').and.returnValue(publicAdvanceRequestRes.data); - expect(utilityService.sortAllAdvances(1, SortingParam.creationDate, publicAdvanceRequestRes.data)).toEqual( - publicAdvanceRequestRes.data + spyOn(lodash, 'cloneDeep').and.returnValue(allAdvanceRequestsRes.data); + expect(utilityService.sortAllAdvances(1, SortingParam.creationDate, allAdvanceRequestsRes.data)).toEqual( + allAdvanceRequestsRes.data ); - expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(publicAdvanceRequestRes.data); + expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(allAdvanceRequestsRes.data); }); it('should sort advances by approval date', () => { - spyOn(lodash, 'cloneDeep').and.returnValue(publicAdvanceRequestRes.data); - expect(utilityService.sortAllAdvances(1, SortingParam.approvalDate, publicAdvanceRequestRes.data)).toEqual( - publicAdvanceRequestRes.data + spyOn(lodash, 'cloneDeep').and.returnValue(allAdvanceRequestsRes.data); + expect(utilityService.sortAllAdvances(1, SortingParam.approvalDate, allAdvanceRequestsRes.data)).toEqual( + allAdvanceRequestsRes.data ); - expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(publicAdvanceRequestRes.data); + expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(allAdvanceRequestsRes.data); }); it('should sort advances by project', () => { - spyOn(lodash, 'cloneDeep').and.returnValue(publicAdvanceRequestRes.data); + spyOn(lodash, 'cloneDeep').and.returnValue(allAdvanceRequestsRes.data); expect( - utilityService.sortAllAdvances(SortingDirection.ascending, SortingParam.project, publicAdvanceRequestRes.data) - ).toEqual(publicAdvanceRequestRes.data); - expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(publicAdvanceRequestRes.data); + utilityService.sortAllAdvances(SortingDirection.ascending, SortingParam.project, allAdvanceRequestsRes.data) + ).toEqual(allAdvanceRequestsRes.data); + expect(lodash.cloneDeep).toHaveBeenCalledOnceWith(allAdvanceRequestsRes.data); }); }); diff --git a/src/app/core/services/utility.service.ts b/src/app/core/services/utility.service.ts index faa123a866..b771fbd5ba 100644 --- a/src/app/core/services/utility.service.ts +++ b/src/app/core/services/utility.service.ts @@ -9,7 +9,6 @@ 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', @@ -125,8 +124,8 @@ export class UtilityService { sortAllAdvances( sortDir: SortingDirection, sortParam: SortingParam, - advancesArray: ExtendedAdvanceRequestPublic[] - ): ExtendedAdvanceRequestPublic[] { + advancesArray: ExtendedAdvanceRequest[] + ): ExtendedAdvanceRequest[] { //used for sorting an array that has both advances and advance requests mixed together const sortedAdvancesArray = cloneDeep(advancesArray); @@ -154,7 +153,7 @@ export class UtilityService { return result; } - private getSortingValue(advance: ExtendedAdvanceRequestPublic, sortParam: SortingParam): dayjs.Dayjs | string { + private getSortingValue(advance: ExtendedAdvanceRequest, 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 c495c260df..26759319b4 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,6 +11,7 @@ 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'; @@ -67,6 +68,7 @@ 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; @@ -93,6 +95,7 @@ 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 cbe45491d7..0b3a486584 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,13 +289,14 @@ 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 { name: customField.name, value: customField.value }; + return { id: customField.id, name: customField.name, value: customField.value }; }); this.customFieldValues = customFields; return this.customFieldValues; @@ -576,10 +577,11 @@ 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.name === customField.name) { + if (customFieldValue.id === customField.id) { 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 452d9f79cb..062d629b5b 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 { publicAdvanceRequestRes, singleExtendedAdvReqRes } from 'src/app/core/mock-data/extended-advance-request.data'; +import { 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.getSpenderAdvanceRequests.and.returnValue(of(publicAdvanceRequestRes)); + advanceRequestService.getMyadvanceRequests.and.returnValue(of(singleExtendedAdvReqRes)); }); it('should get all advances and navigate to add edit advance request page if task count is 1', fakeAsync(() => { @@ -325,9 +325,10 @@ export function TestCases2(getTestBed) { component.onSentBackAdvanceTaskClick(taskCtaData3, mockDashboardTasksData[0]); tick(100); expect(loaderService.showLoader).toHaveBeenCalledOnceWith('Opening your advance request...'); - expect(advanceRequestService.getSpenderAdvanceRequests).toHaveBeenCalledOnceWith({ + expect(advanceRequestService.getMyadvanceRequests).toHaveBeenCalledOnceWith({ queryParams: { - state: 'eq.SENT_BACK', + areq_state: 'in.(DRAFT)', + areq_is_sent_back: 'is.true', }, offset: 0, limit: 1, @@ -337,7 +338,7 @@ export function TestCases2(getTestBed) { '/', 'enterprise', 'add_edit_advance_request', - { id: publicAdvanceRequestRes.data[0].areq_id }, + { id: singleExtendedAdvReqRes.data[0].areq_id }, ]); })); @@ -345,7 +346,7 @@ export function TestCases2(getTestBed) { component.onSentBackAdvanceTaskClick(taskCtaData3, dashboardTasksData[0]); tick(100); expect(loaderService.showLoader).not.toHaveBeenCalled(); - expect(advanceRequestService.getSpenderAdvanceRequests).not.toHaveBeenCalled(); + expect(advanceRequestService.getMyadvanceRequests).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 e2ed5f8479..eb879e0100 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', ['getSpenderAdvanceRequests']); + const advanceRequestServiceSpy = jasmine.createSpyObj('AdvanceRequestService', ['getMyadvanceRequests']); 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 5b0a629877..50db943617 100644 --- a/src/app/fyle/dashboard/tasks/tasks.component.ts +++ b/src/app/fyle/dashboard/tasks/tasks.component.ts @@ -491,12 +491,13 @@ export class TasksComponent implements OnInit { onSentBackAdvanceTaskClick(taskCta: TaskCta, task: DashboardTask): void { if (task.count === 1) { const queryParams = { - state: 'eq.SENT_BACK', + areq_state: 'in.(DRAFT)', + areq_is_sent_back: 'is.true', }; from(this.loaderService.showLoader('Opening your advance request...')) .pipe( - switchMap(() => this.advanceRequestService.getSpenderAdvanceRequests({ queryParams, offset: 0, limit: 1 })), + switchMap(() => this.advanceRequestService.getMyadvanceRequests({ 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 a62dddf543..af68f740b5 100644 --- a/src/app/fyle/my-advances/my-advances.page.spec.ts +++ b/src/app/fyle/my-advances/my-advances.page.spec.ts @@ -18,13 +18,14 @@ 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 { - publicAdvanceRequestRes, - publicAdvanceRequestRes2, - publicAdvanceRequestRes3, - publicAdvanceRequestRes4, - publicAdvanceRequestRes5, - publicAdvanceRequestRes6, - publicAdvanceRequestResSentBack, + allTeamAdvanceRequestsRes, + extendedAdvReqDraft, + extendedAdvReqInquiry, + myAdvanceRequestData5, + myAdvanceRequestsData2, + myAdvanceRequestsData3, + myAdvanceRequestsData4, + singleExtendedAdvReqRes, } from 'src/app/core/mock-data/extended-advance-request.data'; import { singleExtendedAdvancesData, @@ -61,14 +62,14 @@ describe('MyAdvancesPage', () => { beforeEach(waitForAsync(() => { let advanceRequestServiceSpy = jasmine.createSpyObj('AdvanceRequestService', [ - 'getSpenderAdvanceRequestsCount', - 'getSpenderAdvanceRequests', + 'getMyAdvanceRequestsCount', + 'getMyadvanceRequests', 'destroyAdvanceRequestsCacheBuster', ]); let routerSpy = jasmine.createSpyObj('Router', ['navigate']); let advanceServiceSpy = jasmine.createSpyObj('AdvanceService', [ 'getMyAdvancesCount', - 'getSpenderAdvances', + 'getMyadvances', 'destroyAdvancesCacheBuster', ]); let networkServiceSpy = jasmine.createSpyObj('NetworkService', ['connectivityWatcher', 'isOnline']); @@ -197,18 +198,18 @@ describe('MyAdvancesPage', () => { describe('ionViewWillEnter():', () => { beforeEach(() => { spyOn(component, 'setupNetworkWatcher'); - spyOn(component, 'updateMyAdvanceRequests').and.returnValue(publicAdvanceRequestRes.data); + spyOn(component, 'updateMyAdvanceRequests').and.returnValue(singleExtendedAdvReqRes.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.getSpenderAdvanceRequestsCount.and.returnValue(of(1)); - advanceRequestService.getSpenderAdvanceRequests.and.returnValue(of(publicAdvanceRequestRes)); + advanceRequestService.getMyAdvanceRequestsCount.and.returnValue(of(1)); + advanceRequestService.getMyadvanceRequests.and.returnValue(of(singleExtendedAdvReqRes)); advanceService.getMyAdvancesCount.and.returnValue(of(1)); - advanceService.getSpenderAdvances.and.returnValue(of(singleExtendedAdvancesData)); + advanceService.getMyadvances.and.returnValue(of(singleExtendedAdvancesData)); orgSettingsService.get.and.returnValue(of(orgSettingsData)); - utilityService.sortAllAdvances.and.returnValue([publicAdvanceRequestRes3, publicAdvanceRequestRes3]); + utilityService.sortAllAdvances.and.returnValue([extendedAdvReqDraft, extendedAdvReqInquiry]); }); it('should call setupNetworkWatcher() once, set advancesTaskCount to 4, navigateBack to true and totalTaskCount to 5', () => { @@ -227,53 +228,53 @@ describe('MyAdvancesPage', () => { expect(filtersHelperService.generateFilterPills).toHaveBeenCalledOnceWith(component.filterParams$.value); }); - it('should set myAdvancerequests$ to publicAdvanceRequestRes.data', () => { + it('should set myAdvancerequests$ to singleExtendedAdvReqRes.data', () => { component.ionViewWillEnter(); component.myAdvanceRequests$.subscribe((res) => { - expect(advanceRequestService.getSpenderAdvanceRequestsCount).toHaveBeenCalledOnceWith({ - advance_id: 'eq.null', + expect(advanceRequestService.getMyAdvanceRequestsCount).toHaveBeenCalledOnceWith({ + areq_advance_id: 'is.null', }); - expect(advanceRequestService.getSpenderAdvanceRequests).toHaveBeenCalledOnceWith({ + expect(advanceRequestService.getMyadvanceRequests).toHaveBeenCalledOnceWith({ offset: 0, - limit: 200, + limit: 10, queryParams: { - advance_id: 'eq.null', - order: 'created_at.desc,id.desc', + areq_advance_id: 'is.null', + order: 'areq_created_at.desc,areq_id.desc', }, }); - expect(res).toEqual(publicAdvanceRequestRes.data); + expect(res).toEqual(singleExtendedAdvReqRes.data); }); }); - 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) + 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) ); - advanceRequestService.getSpenderAdvanceRequestsCount.and.returnValue(of(201)); + advanceRequestService.getMyAdvanceRequestsCount.and.returnValue(of(11)); component.ionViewWillEnter(); component.myAdvanceRequests$.subscribe((res) => { - expect(advanceRequestService.getSpenderAdvanceRequestsCount).toHaveBeenCalledOnceWith({ - advance_id: 'eq.null', + expect(advanceRequestService.getMyAdvanceRequestsCount).toHaveBeenCalledOnceWith({ + areq_advance_id: 'is.null', }); - expect(advanceRequestService.getSpenderAdvanceRequests).toHaveBeenCalledTimes(2); - expect(advanceRequestService.getSpenderAdvanceRequests).toHaveBeenCalledWith({ + expect(advanceRequestService.getMyadvanceRequests).toHaveBeenCalledTimes(2); + expect(advanceRequestService.getMyadvanceRequests).toHaveBeenCalledWith({ offset: 0, - limit: 200, + limit: 10, queryParams: { - advance_id: 'eq.null', - order: 'created_at.desc,id.desc', + areq_advance_id: 'is.null', + order: 'areq_created_at.desc,areq_id.desc', }, }); - expect(advanceRequestService.getSpenderAdvanceRequests).toHaveBeenCalledWith({ - offset: 200, - limit: 200, + expect(advanceRequestService.getMyadvanceRequests).toHaveBeenCalledWith({ + offset: 10, + limit: 10, queryParams: { - advance_id: 'eq.null', - order: 'created_at.desc,id.desc', + areq_advance_id: 'is.null', + order: 'areq_created_at.desc,areq_id.desc', }, }); - expect(res).toEqual([...publicAdvanceRequestRes2.data, ...publicAdvanceRequestRes2.data]); + expect(res).toEqual([...myAdvanceRequestsData2.data, ...allTeamAdvanceRequestsRes.data]); }); }); @@ -281,11 +282,11 @@ describe('MyAdvancesPage', () => { component.ionViewWillEnter(); component.myAdvances$.subscribe((res) => { expect(advanceService.getMyAdvancesCount).toHaveBeenCalledTimes(1); - expect(advanceService.getSpenderAdvances).toHaveBeenCalledOnceWith({ + expect(advanceService.getMyadvances).toHaveBeenCalledOnceWith({ offset: 0, - limit: 200, + limit: 10, queryParams: { - order: 'created_at.desc,id.desc', + order: 'adv_created_at.desc,adv_id.desc', }, }); expect(res).toEqual(singleExtendedAdvancesData.data); @@ -293,47 +294,44 @@ describe('MyAdvancesPage', () => { }); it('should set myAdvances$ to allTeamAdvanceRequestsRes.data in form of array in case if count is greater than 10', () => { - advanceService.getSpenderAdvances.and.returnValues( - of(singleExtendedAdvancesData2), - of(singleExtendedAdvancesData) - ); - advanceService.getMyAdvancesCount.and.returnValue(of(201)); + advanceService.getMyadvances.and.returnValues(of(singleExtendedAdvancesData2), of(singleExtendedAdvancesData)); + advanceService.getMyAdvancesCount.and.returnValue(of(11)); component.ionViewWillEnter(); component.myAdvances$.subscribe((res) => { expect(advanceService.getMyAdvancesCount).toHaveBeenCalledTimes(1); - expect(advanceService.getSpenderAdvances).toHaveBeenCalledTimes(2); - expect(advanceService.getSpenderAdvances).toHaveBeenCalledWith({ + expect(advanceService.getMyadvances).toHaveBeenCalledTimes(2); + expect(advanceService.getMyadvances).toHaveBeenCalledWith({ offset: 0, - limit: 200, + limit: 10, queryParams: { - order: 'created_at.desc,id.desc', + order: 'adv_created_at.desc,adv_id.desc', }, }); - expect(advanceService.getSpenderAdvances).toHaveBeenCalledWith({ - offset: 200, - limit: 200, + expect(advanceService.getMyadvances).toHaveBeenCalledWith({ + offset: 10, + limit: 10, queryParams: { - order: 'created_at.desc,id.desc', + order: 'adv_created_at.desc,adv_id.desc', }, }); expect(res).toEqual([...singleExtendedAdvancesData2.data, ...singleExtendedAdvancesData.data]); }); }); - it('should set advances$ equals to array containing draft and sent back advance requests', () => { + it('should set advances$ equals to array containing extendedAdvReqDraft, extendedAdvReqInquiry', () => { 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(publicAdvanceRequestRes.data); + expect(component.updateMyAdvanceRequests).toHaveBeenCalledOnceWith(singleExtendedAdvReqRes.data); expect(component.updateMyAdvances).toHaveBeenCalledOnceWith(singleExtendedAdvancesData.data); expect(utilityService.sortAllAdvances).toHaveBeenCalledOnceWith( SortingDirection.ascending, SortingParam.project, [] ); - expect(res).toEqual([publicAdvanceRequestRes3, publicAdvanceRequestRes3]); + expect(res).toEqual([extendedAdvReqDraft, extendedAdvReqInquiry]); }); }); @@ -352,7 +350,7 @@ describe('MyAdvancesPage', () => { SortingParam.project, [] ); - expect(res).toEqual([publicAdvanceRequestRes3, publicAdvanceRequestRes3]); + expect(res).toEqual([extendedAdvReqDraft, extendedAdvReqInquiry]); }); }); @@ -360,8 +358,8 @@ describe('MyAdvancesPage', () => { activatedRoute.snapshot.queryParams.filters = JSON.stringify(draftSentBackFiltersData); component.updateMyAdvanceRequests = jasmine .createSpy() - .and.returnValue([publicAdvanceRequestRes4, publicAdvanceRequestRes6]); - utilityService.sortAllAdvances.and.returnValue([publicAdvanceRequestRes4, publicAdvanceRequestRes6]); + .and.returnValue([myAdvanceRequestsData3, myAdvanceRequestsData4]); + utilityService.sortAllAdvances.and.returnValue([myAdvanceRequestsData4, myAdvanceRequestsData3]); orgSettingsService.get.and.returnValue( of({ ...orgSettingsRes, advance_requests: { enabled: false }, advances: { enabled: false } }) ); @@ -370,10 +368,12 @@ describe('MyAdvancesPage', () => { expect(orgSettingsService.get).toHaveBeenCalledTimes(1); expect(component.updateMyAdvanceRequests).toHaveBeenCalledOnceWith([]); expect(component.updateMyAdvances).toHaveBeenCalledOnceWith([]); - expect(utilityService.sortAllAdvances).toHaveBeenCalledWith(SortingDirection.ascending, SortingParam.project, [ - publicAdvanceRequestRes4, - ]); - expect(res).toEqual([publicAdvanceRequestRes4, publicAdvanceRequestRes6]); + expect(utilityService.sortAllAdvances).toHaveBeenCalledOnceWith( + SortingDirection.ascending, + SortingParam.project, + [myAdvanceRequestsData4, myAdvanceRequestsData3] + ); + expect(res).toEqual([myAdvanceRequestsData4, myAdvanceRequestsData3]); }); }); }); @@ -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(publicAdvanceRequestRes5.data); + const mockMyAdvanceRequestsData = cloneDeep(singleExtendedAdvReqRes.data); const expectedMyAdvanceRequest = component.updateMyAdvanceRequests(mockMyAdvanceRequestsData); - expect(expectedMyAdvanceRequest).toEqual([publicAdvanceRequestRes3]); + expect(expectedMyAdvanceRequest).toEqual([myAdvanceRequestData5]); }); describe('doRefresh():', () => { @@ -421,7 +421,7 @@ describe('MyAdvancesPage', () => { '/', 'enterprise', 'my_view_advance_request', - { id: 'advRhdN9D326Y' }, + { id: 'advETmi3eePvQ' }, ]); }); @@ -434,13 +434,13 @@ describe('MyAdvancesPage', () => { '/', 'enterprise', 'my_view_advance_request', - { id: 'areqrttywiidF8' }, + { id: 'areqmq8cmnd5v4' }, ]); }); it('should navigate to my_view_advance', () => { component.onAdvanceClick({ advanceRequest: singleExtendedAdvancesData3, internalState: { state: 'INQUIRY' } }); - expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'my_view_advance', { id: 'advRhdN9D326Y' }]); + expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'my_view_advance', { id: 'advETmi3eePvQ' }]); }); 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: 'advRhdN9D326Y' }, + { id: 'advETmi3eePvQ' }, ]); }); }); diff --git a/src/app/fyle/my-advances/my-advances.page.ts b/src/app/fyle/my-advances/my-advances.page.ts index a2b355a540..f174f39a02 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 { ExtendedAdvanceRequestPublic } from 'src/app/core/models/extended-advan 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<(ExtendedAdvanceRequestPublic | ExtendedAdvance)[]>; + advances$: Observable<(ExtendedAdvanceRequest | ExtendedAdvance)[]>; isConnected$: Observable; @@ -124,45 +124,45 @@ export class MyAdvancesPage implements AfterViewChecked { this.isLoading = true; this.myAdvanceRequests$ = this.advanceRequestService - .getSpenderAdvanceRequestsCount({ - advance_id: 'eq.null', + .getMyAdvanceRequestsCount({ + areq_advance_id: 'is.null', }) .pipe( concatMap((count) => { - count = count > 200 ? count / 200 : 1; + count = count > 10 ? count / 10 : 1; return range(0, count); }), - concatMap((count) => { - return this.advanceRequestService.getSpenderAdvanceRequests({ - offset: 200 * count, - limit: 200, + concatMap((count) => + this.advanceRequestService.getMyadvanceRequests({ + offset: 10 * count, + limit: 10, queryParams: { - advance_id: 'eq.null', - order: 'created_at.desc,id.desc', + areq_advance_id: 'is.null', + order: 'areq_created_at.desc,areq_id.desc', }, - }); - }), + }) + ), map((res) => res.data), reduce((acc, curr) => acc.concat(curr)) ); this.myAdvances$ = this.advanceService.getMyAdvancesCount().pipe( concatMap((count) => { - count = count > 200 ? count / 200 : 1; + count = count > 10 ? count / 10 : 1; return range(0, count); }), concatMap((count) => - this.advanceService.getSpenderAdvances({ - offset: 200 * count, - limit: 200, - queryParams: { order: 'created_at.desc,id.desc' }, + this.advanceService.getMyadvances({ + offset: 10 * count, + limit: 10, + queryParams: { order: 'adv_created_at.desc,adv_id.desc' }, }) ), map((res) => res.data), reduce((acc, curr) => acc.concat(curr)) ); - const sortResults = map((res: (ExtendedAdvanceRequestPublic | ExtendedAdvance)[]) => + const sortResults = map((res: (ExtendedAdvanceRequest | 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: ExtendedAdvanceRequestPublic[]) => + switchMap((advArray: ExtendedAdvanceRequest[]) => //piping through filterParams so that filtering and sorting happens whenever we call next() on filterParams this.filterParams$.pipe( map((filters) => { @@ -194,7 +194,8 @@ 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 === 'INQUIRY'); + adv.areq_state === 'DRAFT' && + adv.areq_is_sent_back; const plainDraft = filters.state.includes(AdvancesStates.draft) && @@ -238,7 +239,7 @@ export class MyAdvancesPage implements AfterViewChecked { return myAdvances; } - updateMyAdvanceRequests(myAdvanceRequests: ExtendedAdvanceRequestPublic[]): ExtendedAdvanceRequestPublic[] { + updateMyAdvanceRequests(myAdvanceRequests: ExtendedAdvanceRequest[]): ExtendedAdvanceRequest[] { 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 39eb05ef4c..a55098f9ff 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 { publicAdvanceRequestRes } from 'src/app/core/mock-data/extended-advance-request.data'; +import { extendedAdvReqDraft } from 'src/app/core/mock-data/extended-advance-request.data'; import { apiAdvanceRequestAction } from 'src/app/core/mock-data/advance-request-actions.data'; -import { advanceReqApprovals, advanceReqApprovalsPublic } from 'src/app/core/mock-data/approval.data'; +import { advanceReqApprovals } 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', [ - 'getAdvanceRequestPlatform', + 'getAdvanceRequest', 'getActions', 'getInternalStateAndDisplayName', - 'getActiveApproversByAdvanceRequestIdPlatform', + 'getActiveApproversByAdvanceRequestId', 'modifyAdvanceRequestCustomFields', 'pullBackAdvanceRequest', 'delete', @@ -175,13 +175,13 @@ describe('MyViewAdvanceRequestPage', () => { beforeEach(() => { loaderService.showLoader.and.resolveTo(); loaderService.hideLoader.and.resolveTo(); - advanceRequestService.getAdvanceRequestPlatform.and.returnValue(of(publicAdvanceRequestRes.data[0])); + advanceRequestService.getAdvanceRequest.and.returnValue(of(extendedAdvReqDraft)); advanceRequestService.getInternalStateAndDisplayName.and.returnValue({ state: 'DRAFT', name: 'Draft', }); advanceRequestService.getActions.and.returnValue(of(apiAdvanceRequestAction)); - advanceRequestService.getActiveApproversByAdvanceRequestIdPlatform.and.returnValue(of(advanceReqApprovalsPublic)); + advanceRequestService.getActiveApproversByAdvanceRequestId.and.returnValue(of(advanceReqApprovals)); const mockFileObject = cloneDeep(advanceRequestFileUrlData[0]); spyOn(component, 'getReceiptDetails').and.returnValue({ type: 'pdf', @@ -200,14 +200,12 @@ describe('MyViewAdvanceRequestPage', () => { tick(100); component.advanceRequest$.subscribe((res) => { - expect(advanceRequestService.getAdvanceRequestPlatform).toHaveBeenCalledOnceWith('areqR1cyLgXdND'); + expect(advanceRequestService.getAdvanceRequest).toHaveBeenCalledOnceWith('areqR1cyLgXdND'); expect(loaderService.showLoader).toHaveBeenCalledTimes(1); expect(loaderService.hideLoader).toHaveBeenCalledTimes(1); - expect(res).toEqual(publicAdvanceRequestRes.data[0]); + expect(res).toEqual(extendedAdvReqDraft); }); - expect(advanceRequestService.getInternalStateAndDisplayName).toHaveBeenCalledOnceWith( - publicAdvanceRequestRes.data[0] - ); + expect(advanceRequestService.getInternalStateAndDisplayName).toHaveBeenCalledOnceWith(extendedAdvReqDraft); expect(component.internalState).toEqual({ state: 'DRAFT', name: 'Draft', @@ -216,7 +214,7 @@ describe('MyViewAdvanceRequestPage', () => { })); it('should set currency symbol to undefined if advance request is undefined', fakeAsync(() => { - advanceRequestService.getAdvanceRequestPlatform.and.returnValue(of(undefined)); + advanceRequestService.getAdvanceRequest.and.returnValue(of(undefined)); component.ionViewWillEnter(); tick(100); @@ -242,11 +240,9 @@ describe('MyViewAdvanceRequestPage', () => { tick(100); component.activeApprovals$.subscribe((res) => { - expect(res).toEqual(advanceReqApprovalsPublic); + expect(res).toEqual(advanceReqApprovals); }); - expect(advanceRequestService.getActiveApproversByAdvanceRequestIdPlatform).toHaveBeenCalledOnceWith( - 'areqR1cyLgXdND' - ); + expect(advanceRequestService.getActiveApproversByAdvanceRequestId).toHaveBeenCalledOnceWith('areqR1cyLgXdND'); })); it('should set attachedFiles$ to attached files', fakeAsync(() => { @@ -267,12 +263,11 @@ describe('MyViewAdvanceRequestPage', () => { advanceRequestsCustomFieldsService.getAll.and.returnValue(of(mockAdvRequestCustomFields)); component.ionViewWillEnter(); - tick(100); component.advanceRequestCustomFields$.subscribe(() => { expect(advanceRequestService.modifyAdvanceRequestCustomFields).toHaveBeenCalledOnceWith( - publicAdvanceRequestRes.data[0].areq_custom_field_values + JSON.parse(extendedAdvReqDraft.areq_custom_field_values) ); expect(advanceRequestsCustomFieldsService.getAll).toHaveBeenCalledTimes(1); }); @@ -328,7 +323,7 @@ describe('MyViewAdvanceRequestPage', () => { describe('openCommentsModal():', () => { let commentsModalSpy: jasmine.SpyObj; beforeEach(() => { - component.advanceRequest$ = of(publicAdvanceRequestRes.data[0]); + component.advanceRequest$ = of(extendedAdvReqDraft); 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 780348aeac..0d4bb4d649 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,7 +3,9 @@ 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'; @@ -19,8 +21,6 @@ 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 { ApprovalPublic } from 'src/app/core/models/approval-public.model'; 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.getAdvanceRequestPlatform(id)), + switchMap(() => this.advanceRequestService.getAdvanceRequest(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.getActiveApproversByAdvanceRequestIdPlatform(id); + this.activeApprovals$ = this.advanceRequestService.getActiveApproversByAdvanceRequestId(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( - res.advanceRequest.areq_custom_field_values + JSON.parse(res.advanceRequest.areq_custom_field_values) ); } res.customFields.map((customField) => { customFieldValues.filter((customFieldValue) => { - if (customField.name === customFieldValue.name) { + if (customField.id === customFieldValue.id) { customField.value = customFieldValue.value; } });