1
0

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.
This commit is contained in:
Ahmed Bouhuolia
2026-03-05 23:02:28 +02:00
parent ef24372c85
commit 125e00e139
6 changed files with 162 additions and 309 deletions
@@ -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,
};
}
@@ -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,
);
}
@@ -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,
},
);
}
@@ -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,
},
);
}
+106 -9
View File
@@ -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 <token>' where <token> 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": {
+56 -6
View File
@@ -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 <token>' where <token> 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"][];
};
};
};
};