mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-04-19 10:44:06 +00:00
feat: add response DTOs for credit note modules and SDK types
This commit is contained in:
@@ -24,6 +24,10 @@ export type ValidateBulkDeleteCreditNotesBody = OpRequestBody<OpForPath<typeof C
|
||||
export type ValidateBulkDeleteCreditNotesResponse = OpResponseBody<OpForPath<typeof CREDIT_NOTES_ROUTES.VALIDATE_BULK_DELETE, 'post'>>;
|
||||
export type BulkDeleteCreditNotesBody = OpRequestBody<OpForPath<typeof CREDIT_NOTES_ROUTES.BULK_DELETE, 'post'>>;
|
||||
export type CreateRefundCreditNoteBody = OpRequestBody<OpForPath<typeof CREDIT_NOTES_ROUTES.REFUNDS, 'post'>>;
|
||||
export type CreditNoteRefundsResponse = OpResponseBody<OpForPath<typeof CREDIT_NOTES_ROUTES.REFUNDS, 'get'>>;
|
||||
export type RefundCreditNoteTransaction = OpResponseBody<OpForPath<typeof CREDIT_NOTES_ROUTES.REFUND_BY_ID, 'get'>>;
|
||||
export type AppliedCreditNoteInvoicesResponse = OpResponseBody<OpForPath<typeof CREDIT_NOTES_ROUTES.APPLIED_INVOICES, 'get'>>;
|
||||
export type CreditNoteInvoicesToApplyResponse = OpResponseBody<OpForPath<typeof CREDIT_NOTES_ROUTES.APPLY_INVOICES, 'get'>>;
|
||||
export type ApplyCreditNoteToInvoicesBody = OpRequestBody<OpForPath<typeof CREDIT_NOTES_ROUTES.APPLY_INVOICES, 'post'>>;
|
||||
export type GetCreditNotesQuery = OpQueryParams<OpForPath<typeof CREDIT_NOTES_ROUTES.LIST, 'get'>>;
|
||||
|
||||
@@ -96,9 +100,10 @@ export async function bulkDeleteCreditNotes(
|
||||
export async function fetchCreditNoteRefunds(
|
||||
fetcher: ApiFetcher,
|
||||
creditNoteId: number
|
||||
): Promise<void> {
|
||||
): Promise<CreditNoteRefundsResponse> {
|
||||
const getRefunds = fetcher.path(CREDIT_NOTES_ROUTES.REFUNDS).method('get').create();
|
||||
await getRefunds({ creditNoteId });
|
||||
const { data } = await getRefunds({ creditNoteId });
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function createRefundCreditNote(
|
||||
@@ -121,17 +126,28 @@ export async function deleteRefundCreditNote(
|
||||
export async function fetchAppliedInvoices(
|
||||
fetcher: ApiFetcher,
|
||||
creditNoteId: number
|
||||
): Promise<void> {
|
||||
): Promise<AppliedCreditNoteInvoicesResponse> {
|
||||
const getApplied = fetcher.path(CREDIT_NOTES_ROUTES.APPLIED_INVOICES).method('get').create();
|
||||
await getApplied({ creditNoteId });
|
||||
const { data } = await getApplied({ creditNoteId });
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchCreditNoteAssociatedInvoicesToApply(
|
||||
fetcher: ApiFetcher,
|
||||
creditNoteId: number
|
||||
): Promise<void> {
|
||||
): Promise<CreditNoteInvoicesToApplyResponse> {
|
||||
const get = fetcher.path(CREDIT_NOTES_ROUTES.APPLY_INVOICES).method('get').create();
|
||||
await get({ creditNoteId });
|
||||
const { data } = await get({ creditNoteId });
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchRefundCreditNoteTransaction(
|
||||
fetcher: ApiFetcher,
|
||||
refundCreditId: number
|
||||
): Promise<RefundCreditNoteTransaction> {
|
||||
const get = fetcher.path(CREDIT_NOTES_ROUTES.REFUND_BY_ID).method('get').create();
|
||||
const { data } = await get({ refundCreditId });
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function applyCreditNoteToInvoices(
|
||||
|
||||
@@ -43,6 +43,7 @@ export * from './landed-cost';
|
||||
export * from './generic-resource';
|
||||
export * from './cashflow-accounts';
|
||||
export * from './bank-rules';
|
||||
export * from './misc';
|
||||
export * from './reports';
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ApiFetcher } from './fetch-utils';
|
||||
import { paths } from './schema';
|
||||
import { OpForPath, OpRequestBody, OpResponseBody } from './utils';
|
||||
import { OpForPath, OpQueryParams, OpRequestBody, OpResponseBody } from './utils';
|
||||
|
||||
export const INVENTORY_ADJUSTMENTS_ROUTES = {
|
||||
LIST: '/api/inventory-adjustments',
|
||||
@@ -12,10 +12,16 @@ export const INVENTORY_ADJUSTMENTS_ROUTES = {
|
||||
export type InventoryAdjustmentsListResponse = OpResponseBody<OpForPath<typeof INVENTORY_ADJUSTMENTS_ROUTES.LIST, 'get'>>;
|
||||
export type InventoryAdjustment = OpResponseBody<OpForPath<typeof INVENTORY_ADJUSTMENTS_ROUTES.BY_ID, 'get'>>;
|
||||
export type CreateQuickInventoryAdjustmentBody = OpRequestBody<OpForPath<typeof INVENTORY_ADJUSTMENTS_ROUTES.QUICK, 'post'>>;
|
||||
export type GetInventoryAdjustmentsQuery = OpQueryParams<OpForPath<typeof INVENTORY_ADJUSTMENTS_ROUTES.LIST, 'get'>>;
|
||||
|
||||
export async function fetchInventoryAdjustments(fetcher: ApiFetcher): Promise<InventoryAdjustmentsListResponse> {
|
||||
export async function fetchInventoryAdjustments(
|
||||
fetcher: ApiFetcher,
|
||||
query?: GetInventoryAdjustmentsQuery
|
||||
): Promise<InventoryAdjustmentsListResponse> {
|
||||
const get = fetcher.path(INVENTORY_ADJUSTMENTS_ROUTES.LIST).method('get').create();
|
||||
const { data } = await get({});
|
||||
const { data } = await (get as (params?: GetInventoryAdjustmentsQuery) => Promise<{ data: InventoryAdjustmentsListResponse }>)(
|
||||
query ?? {}
|
||||
);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
19
shared/sdk-ts/src/misc.ts
Normal file
19
shared/sdk-ts/src/misc.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { ApiFetcher } from './fetch-utils';
|
||||
import { paths } from './schema';
|
||||
import { OpForPath, OpResponseBody } from './utils';
|
||||
|
||||
export const MISC_ROUTES = {
|
||||
DATE_FORMATS: '/api/date-formats',
|
||||
} as const satisfies Record<string, keyof paths>;
|
||||
|
||||
export type DateFormatsResponse = OpResponseBody<
|
||||
OpForPath<typeof MISC_ROUTES.DATE_FORMATS, 'get'>
|
||||
>;
|
||||
|
||||
export async function fetchDateFormats(
|
||||
fetcher: ApiFetcher,
|
||||
): Promise<DateFormatsResponse> {
|
||||
const get = fetcher.path(MISC_ROUTES.DATE_FORMATS).method('get').create();
|
||||
const { data } = await get({});
|
||||
return data;
|
||||
}
|
||||
@@ -11,6 +11,7 @@ export const ORGANIZATION_ROUTES = {
|
||||
} as const satisfies Record<string, keyof paths>;
|
||||
|
||||
export type OrganizationCurrent = OpResponseBody<OpForPath<typeof ORGANIZATION_ROUTES.CURRENT, 'get'>>;
|
||||
export type OrganizationBuildJob = OpResponseBody<OpForPath<typeof ORGANIZATION_ROUTES.BUILD_JOB, 'get'>>;
|
||||
export type UpdateOrganizationBody = OpRequestBody<OpForPath<typeof ORGANIZATION_ROUTES.UPDATE, 'put'>>;
|
||||
|
||||
export async function fetchOrganizationCurrent(fetcher: ApiFetcher): Promise<OrganizationCurrent> {
|
||||
@@ -31,3 +32,12 @@ export type Organization = OrganizationCurrent;
|
||||
export async function fetchOrganization(fetcher: ApiFetcher): Promise<Organization> {
|
||||
return fetchOrganizationCurrent(fetcher);
|
||||
}
|
||||
|
||||
export async function fetchOrganizationBuildJob(
|
||||
fetcher: ApiFetcher,
|
||||
buildJobId: number | string
|
||||
): Promise<OrganizationBuildJob> {
|
||||
const get = fetcher.path(ORGANIZATION_ROUTES.BUILD_JOB).method('get').create();
|
||||
const { data } = await get({ buildJobId: Number(buildJobId) });
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user