From 125e00e1394f67fa8e9ce7e1a154fb111f84b7a2 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Thu, 5 Mar 2026 23:02:28 +0200 Subject: [PATCH] chore: remove unused query hooks and update OpenAPI schema - Deleted unused hooks for exchange rates, inventory adjustments, landed cost, and universal search. - Updated OpenAPI schema to include new endpoints for vendor credits and enhanced response structures for bank transactions. --- .../query/UniversalSearch/UniversalSearch.tsx | 42 ------ .../webapp/src/hooks/query/exchangeRates.tsx | 36 ----- .../src/hooks/query/inventoryAdjustments.tsx | 128 ------------------ .../webapp/src/hooks/query/landedCost.tsx | 88 ------------ shared/sdk-ts/openapi.json | 115 ++++++++++++++-- shared/sdk-ts/src/schema.ts | 62 ++++++++- 6 files changed, 162 insertions(+), 309 deletions(-) delete mode 100644 packages/webapp/src/hooks/query/UniversalSearch/UniversalSearch.tsx delete mode 100644 packages/webapp/src/hooks/query/exchangeRates.tsx delete mode 100644 packages/webapp/src/hooks/query/inventoryAdjustments.tsx delete mode 100644 packages/webapp/src/hooks/query/landedCost.tsx diff --git a/packages/webapp/src/hooks/query/UniversalSearch/UniversalSearch.tsx b/packages/webapp/src/hooks/query/UniversalSearch/UniversalSearch.tsx deleted file mode 100644 index 48b437811..000000000 --- a/packages/webapp/src/hooks/query/UniversalSearch/UniversalSearch.tsx +++ /dev/null @@ -1,42 +0,0 @@ -// @ts-nocheck -import { getUniversalSearchBind } from '@/containers/UniversalSearch/utils'; -import { useResourceData } from '../GenericResource'; - -/** - * Transformes the resource data to search entries based on - * the given resource type. - * @param {string} type - * @param {any} resource - * @returns - */ -function transfromResourceDataToSearch(resource) { - const selectItem = getUniversalSearchBind(resource._type, 'itemSelect'); - - return resource.items - .map((item) => ({ - ...selectItem ? selectItem(item) : {}, - _type: resource._type, - })); -} - -/** - * - * @param {*} type - * @param {*} searchKeyword - * @returns - */ -export function useUniversalSearch(type, searchKeyword, props) { - const { data, ...restProps } = useResourceData( - type, - { - search_keyword: searchKeyword, - }, - props, - ); - const searchData = transfromResourceDataToSearch(data); - - return { - data: searchData, - ...restProps, - }; -} diff --git a/packages/webapp/src/hooks/query/exchangeRates.tsx b/packages/webapp/src/hooks/query/exchangeRates.tsx deleted file mode 100644 index 36700276b..000000000 --- a/packages/webapp/src/hooks/query/exchangeRates.tsx +++ /dev/null @@ -1,36 +0,0 @@ -// @ts-nocheck -import { useQuery } from 'react-query'; -import QUERY_TYPES from './types'; -import useApiRequest from '../useRequest'; - -interface LatestExchangeRateQuery { - fromCurrency?: string; - toCurrency?: string; -} - -/** - * Retrieves latest exchange rate. - * @param {number} customerId - Customer id. - */ -export function useLatestExchangeRate( - { toCurrency, fromCurrency }: LatestExchangeRateQuery, - props, -) { - const apiRequest = useApiRequest(); - - return useQuery( - [QUERY_TYPES.EXCHANGE_RATE, toCurrency, fromCurrency], - () => - apiRequest - .http({ - url: `/api/exchange_rates/latest`, - method: 'get', - params: { - to_currency: toCurrency, - from_currency: fromCurrency, - }, - }) - .then((res) => res.data), - props, - ); -} diff --git a/packages/webapp/src/hooks/query/inventoryAdjustments.tsx b/packages/webapp/src/hooks/query/inventoryAdjustments.tsx deleted file mode 100644 index 638c6e69b..000000000 --- a/packages/webapp/src/hooks/query/inventoryAdjustments.tsx +++ /dev/null @@ -1,128 +0,0 @@ -// @ts-nocheck -import { useMutation, useQueryClient } from 'react-query'; -import { useRequestQuery } from '../useQueryRequest'; -import { transformPagination } from '@/utils'; -import useApiRequest from '../useRequest'; -import t from './types'; - -const commonInvalidateQueries = (queryClient) => { - // Invalidate inventory adjustments. - queryClient.invalidateQueries(t.INVENTORY_ADJUSTMENTS); - queryClient.invalidateQueries(t.INVENTORY_ADJUSTMENT); - - // Invalidate items. - queryClient.invalidateQueries(t.ITEMS); - queryClient.invalidateQueries(t.ITEM); - - // Invalidate accounts. - queryClient.invalidateQueries(t.ACCOUNTS); - queryClient.invalidateQueries(t.ACCOUNT); - - // Invalidate financial reports. - queryClient.invalidateQueries(t.FINANCIAL_REPORT); - - // Invalidate mutate base currency abilities. - queryClient.invalidateQueries(t.ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES); -}; - -/** - * Creates the inventory adjustment to the given item. - */ -export function useCreateInventoryAdjustment(props) { - const queryClient = useQueryClient(); - const apiRequest = useApiRequest(); - - return useMutation( - (values) => apiRequest.post('inventory-adjustments/quick', values), - { - onSuccess: () => { - // Common invalidate queries. - commonInvalidateQueries(queryClient); - }, - ...props, - }, - ); -} - -/** - * Deletes the inventory adjustment transaction. - */ -export function useDeleteInventoryAdjustment(props) { - const queryClient = useQueryClient(); - const apiRequest = useApiRequest(); - - return useMutation((id) => apiRequest.delete(`inventory-adjustments/${id}`), { - onSuccess: (res, id) => { - // Common invalidate queries. - commonInvalidateQueries(queryClient); - }, - ...props, - }); -} - -const inventoryAdjustmentsTransformer = (response) => { - return { - inventoryAdjustments: response.data.data, - pagination: transformPagination(response.data.pagination), - }; -}; - -/** - * Retrieve inventory adjustment list with pagination meta. - */ -export function useInventoryAdjustments(query, props) { - return useRequestQuery( - ['inventory-adjustments', query], - { url: 'inventory-adjustments', params: query }, - { - select: inventoryAdjustmentsTransformer, - defaultData: { - transactions: [], - pagination: { - page: 1, - pageSize: 20, - total: 0, - pagesCount: 0, - }, - }, - ...props, - }, - ); -} - -/** - * Publishes the given inventory adjustment. - */ -export function usePublishInventoryAdjustment(props) { - const queryClient = useQueryClient(); - const apiRequest = useApiRequest(); - - return useMutation( - (id) => apiRequest.post(`inventory-adjustments/${id}/publish`), - { - onSuccess: (res, id) => { - // Invalidate specific inventory adjustment. - queryClient.invalidateQueries([t.INVENTORY_ADJUSTMENT, id]); - - commonInvalidateQueries(queryClient); - }, - ...props, - }, - ); -} - -/** - * Retrieve the inventory adjustment details. - * @param {number} id - inventory adjustment id. - */ -export function useInventoryAdjustment(id, props, requestProps) { - return useRequestQuery( - [t.INVENTORY_ADJUSTMENT, id], - { method: 'get', url: `inventory-adjustments/${id}`, ...requestProps }, - { - select: (res) => res.data, - defaultData: {}, - ...props, - }, - ); -} diff --git a/packages/webapp/src/hooks/query/landedCost.tsx b/packages/webapp/src/hooks/query/landedCost.tsx deleted file mode 100644 index b3e217e08..000000000 --- a/packages/webapp/src/hooks/query/landedCost.tsx +++ /dev/null @@ -1,88 +0,0 @@ -// @ts-nocheck -import { useQueryClient, useMutation } from 'react-query'; -import useApiRequest from '../useRequest'; -import { useRequestQuery } from '../useQueryRequest'; - -import t from './types'; - -const commonInvalidateQueries = (queryClient) => { - // Invalidate bills. - queryClient.invalidateQueries(t.BILLS); - queryClient.invalidateQueries(t.BILL); - // Invalidate landed cost. - queryClient.invalidateQueries(t.LANDED_COST); - queryClient.invalidateQueries(t.LANDED_COST_TRANSACTION); -}; - -/** - * Creates a new landed cost. - */ -export function useCreateLandedCost(props) { - const queryClient = useQueryClient(); - const apiRequest = useApiRequest(); - - return useMutation( - ([id, values]) => - apiRequest.post(`landed-cost/bills/${id}/allocate`, values), - { - onSuccess: (res, id) => { - // Common invalidate queries. - commonInvalidateQueries(queryClient); - }, - ...props, - }, - ); -} - -/** - * Deletes the given landed cost. - */ -export function useDeleteLandedCost(props) { - const queryClient = useQueryClient(); - const apiRequest = useApiRequest(); - - return useMutation( - (landedCostId) => - apiRequest.delete(`landed-cost/${landedCostId}`), - { - onSuccess: (res, id) => { - // Common invalidate queries. - commonInvalidateQueries(queryClient); - }, - ...props, - }, - ); -} - -/** - * Retrieve the landed cost transactions. - */ -export function useLandedCostTransaction(query, props) { - return useRequestQuery( - [t.LANDED_COST, query], - { - method: 'get', - url: 'landed-cost/transactions', - params: { transaction_type: query }, - }, - { - select: (res) => res.data, - ...props, - }, - ); -} - -/** - * Retrieve the bill located landed cost transactions. - */ -export function useBillLocatedLandedCost(id, props) { - return useRequestQuery( - [t.LANDED_COST_TRANSACTION, id], - { method: 'get', url: `landed-cost/bills/${id}/transactions` }, - { - select: (res) => res.data?.data, - defaultData: [], - ...props, - }, - ); -} diff --git a/shared/sdk-ts/openapi.json b/shared/sdk-ts/openapi.json index 6020d0f51..0f691b98b 100644 --- a/shared/sdk-ts/openapi.json +++ b/shared/sdk-ts/openapi.json @@ -11329,6 +11329,47 @@ } }, "/api/vendor-credits/refunds/{refundCreditId}": { + "get": { + "operationId": "VendorCreditsRefundController_getRefundVendorCreditTransaction", + "summary": "Retrieve a refund vendor credit transaction by id.", + "parameters": [ + { + "name": "Authorization", + "in": "header", + "description": "Value must be 'Bearer ' where is an API key prefixed with 'bc_' or a JWT token.", + "required": true, + "schema": { + "type": "string", + "example": "Bearer bc_1234567890abcdef" + } + }, + { + "name": "organization-id", + "in": "header", + "description": "Required if Authorization is a JWT token. The organization ID to operate within.", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "refundCreditId", + "required": true, + "in": "path", + "schema": { + "type": "number" + } + } + ], + "responses": { + "200": { + "description": "" + } + }, + "tags": [ + "Vendor Credits Refunds" + ] + }, "delete": { "operationId": "VendorCreditsRefundController_deleteRefundVendorCredit", "summary": "Delete a refund for the given vendor credit.", @@ -12492,7 +12533,17 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/GetPendingTransactionResponseDto" + "allOf": [ + { "$ref": "#/components/schemas/PaginatedResponseDto" }, + { + "properties": { + "data": { + "type": "array", + "items": { "$ref": "#/components/schemas/GetPendingTransactionResponseDto" } + } + } + } + ] } } } @@ -12832,10 +12883,17 @@ "content": { "application/json": { "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/GetRecognizedTransactionResponseDto" - } + "allOf": [ + { "$ref": "#/components/schemas/PaginatedResponseDto" }, + { + "properties": { + "data": { + "type": "array", + "items": { "$ref": "#/components/schemas/GetRecognizedTransactionResponseDto" } + } + } + } + ] } } } @@ -12871,6 +12929,16 @@ } } ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ExcludeBankTransactionsBulkDto" + } + } + } + }, "responses": { "200": { "description": "" @@ -12904,6 +12972,16 @@ } } ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ExcludeBankTransactionsBulkDto" + } + } + } + }, "responses": { "200": { "description": "" @@ -12945,10 +13023,17 @@ "content": { "application/json": { "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/GetExcludedBankTransactionResponseDto" - } + "allOf": [ + { "$ref": "#/components/schemas/PaginatedResponseDto" }, + { + "properties": { + "data": { + "type": "array", + "items": { "$ref": "#/components/schemas/GetExcludedBankTransactionResponseDto" } + } + } + } + ] } } } @@ -45120,6 +45205,18 @@ "bankRuleName" ] }, + "ExcludeBankTransactionsBulkDto": { + "type": "object", + "required": ["ids"], + "properties": { + "ids": { + "type": "array", + "items": { "type": "number" }, + "description": "IDs of uncategorized bank transactions to exclude or unexclude", + "example": [1, 2, 3] + } + } + }, "GetExcludedBankTransactionResponseDto": { "type": "object", "properties": { diff --git a/shared/sdk-ts/src/schema.ts b/shared/sdk-ts/src/schema.ts index 3d4d61c05..2e716b40e 100644 --- a/shared/sdk-ts/src/schema.ts +++ b/shared/sdk-ts/src/schema.ts @@ -3018,7 +3018,8 @@ export interface paths { path?: never; cookie?: never; }; - get?: never; + /** Retrieve a refund vendor credit transaction by id. */ + get: operations["VendorCreditsRefundController_getRefundVendorCreditTransaction"]; put?: never; post?: never; /** Delete a refund for the given vendor credit. */ @@ -11258,6 +11259,17 @@ export interface components { */ bankRuleName: string; }; + ExcludeBankTransactionsBulkDto: { + /** + * @description IDs of uncategorized bank transactions to exclude or unexclude + * @example [ + * 1, + * 2, + * 3 + * ] + */ + ids: number[]; + }; GetExcludedBankTransactionResponseDto: { /** @description Transaction amount (positive for deposit, negative for withdrawal) */ amount: number; @@ -18847,6 +18859,30 @@ export interface operations { }; }; }; + VendorCreditsRefundController_getRefundVendorCreditTransaction: { + parameters: { + query?: never; + header: { + /** @description Value must be 'Bearer ' where is an API key prefixed with 'bc_' or a JWT token. */ + Authorization: string; + /** @description Required if Authorization is a JWT token. The organization ID to operate within. */ + "organization-id": string; + }; + path: { + refundCreditId: number; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + 200: { + headers: { + [name: string]: unknown; + }; + content?: never; + }; + }; + }; VendorCreditsRefundController_deleteRefundVendorCredit: { parameters: { query?: never; @@ -19447,7 +19483,9 @@ export interface operations { [name: string]: unknown; }; content: { - "application/json": components["schemas"]["GetPendingTransactionResponseDto"]; + "application/json": components["schemas"]["PaginatedResponseDto"] & { + data?: components["schemas"]["GetPendingTransactionResponseDto"][]; + }; }; }; }; @@ -19644,7 +19682,9 @@ export interface operations { [name: string]: unknown; }; content: { - "application/json": components["schemas"]["GetRecognizedTransactionResponseDto"][]; + "application/json": components["schemas"]["PaginatedResponseDto"] & { + data?: components["schemas"]["GetRecognizedTransactionResponseDto"][]; + }; }; }; }; @@ -19661,7 +19701,11 @@ export interface operations { path?: never; cookie?: never; }; - requestBody?: never; + requestBody: { + content: { + "application/json": components["schemas"]["ExcludeBankTransactionsBulkDto"]; + }; + }; responses: { 200: { headers: { @@ -19683,7 +19727,11 @@ export interface operations { path?: never; cookie?: never; }; - requestBody?: never; + requestBody: { + content: { + "application/json": components["schemas"]["ExcludeBankTransactionsBulkDto"]; + }; + }; responses: { 200: { headers: { @@ -19713,7 +19761,9 @@ export interface operations { [name: string]: unknown; }; content: { - "application/json": components["schemas"]["GetExcludedBankTransactionResponseDto"][]; + "application/json": components["schemas"]["PaginatedResponseDto"] & { + data?: components["schemas"]["GetExcludedBankTransactionResponseDto"][]; + }; }; }; };