UNPKG

@accounter/server

Version:
74 lines (73 loc) 4.71 kB
import DataLoader from 'dataloader'; import { type IDatabaseConnection } from '@pgtyped/runtime'; import type { Optional, TimelessDateString } from '../../../shared/types/index.js'; import { TenantAwareDBClient } from '../../app-providers/tenant-db-client.js'; import type { IBatchUpdateChargesParams, IDeleteChargesByIdsParams, IGenerateChargeParams, IGetChargesByFiltersParams, IGetChargesByFiltersResult, IGetSimilarChargesParams, IUpdateAccountantApprovalParams, IUpdateChargeParams } from '../types.js'; import { ChargesAuthorizationProvider } from './charges-authorization.provider.js'; export type ChargeRequiredWrapper<T extends { id: unknown; owner_id: unknown; is_property: unknown; accountant_status: unknown; updated_at: unknown; created_at: unknown; documents_optional_flag: unknown; optional_vat: unknown; }> = Omit<T, 'id' | 'owner_id' | 'is_property' | 'accountant_status' | 'updated_at' | 'created_at' | 'documents_optional_flag' | 'optional_vat'> & { id: NonNullable<T['id']>; owner_id: NonNullable<T['owner_id']>; is_property: NonNullable<T['is_property']>; accountant_status: NonNullable<T['accountant_status']>; updated_at: NonNullable<T['updated_at']>; created_at: NonNullable<T['created_at']>; documents_optional_flag: NonNullable<T['documents_optional_flag']>; optional_vat: NonNullable<T['optional_vat']>; }; /** * Collapses a search string that is empty once trimmed to `null`. * * An empty string is not `NULL` in SQL, so it survives the `IS NOT NULL` guards and * degrades to `ILIKE '%%'`, which matches every non-null column. On the exclusion side * that drops nearly every charge; on the positive side it drops the opposite set -- * charges whose description is `NULL` -- because they fail the `ILIKE` the others pass. * Either way the caller meant "no text predicate", so normalize it away. */ export declare function normalizeSearchText(text?: string | null | void): string | null; /** * The amount-matching branches compare against `amount::TEXT`, so a search term with * no digit in it cannot match one and only costs a scan. Thousands separators are * stripped so both "1,234.56" and "1234.56" match the plain stored value. */ export declare function toNumericSearchText(text: string | null): string | null; type IGetAdjustedChargesByFiltersParams = Optional<Omit<IGetChargesByFiltersParams, 'isOwnerIds' | 'isBusinessIds' | 'businessIds' | 'isIDs' | 'isTags' | 'tags' | 'isBusinessTripIds' | 'businessTripIds' | 'isAccountIds' | 'accountIds' | 'freeTextNumeric' | 'isExcludedBusinessIds' | 'excludedBusinessIds' | 'isExcludedTags' | 'excludedTags' | 'isExcludedAccountIds' | 'excludedAccountIds' | 'excludedFreeTextNumeric'>, 'ownerIds' | 'IDs' | 'asc' | 'sortColumn' | 'toDate' | 'fromDate'> & { toDate?: TimelessDateString | null; fromDate?: TimelessDateString | null; tags?: readonly string[] | null; businessIds?: readonly string[] | null; businessTripIds?: readonly string[] | null; accountIds?: readonly string[] | null; excludedBusinessIds?: readonly string[] | null; excludedTags?: readonly string[] | null; excludedAccountIds?: readonly string[] | null; }; export declare class ChargesProvider { private db; private auth; constructor(db: TenantAwareDBClient, auth: ChargesAuthorizationProvider); private batchChargesByIds; getChargeByIdLoader: DataLoader<string, import("../types.js").IGetChargesByIdsResult | undefined, string>; private batchChargesByTransactionIds; getChargeByTransactionIdLoader: DataLoader<string, import("../types.js").IGetChargesByTransactionIdsResult | undefined, string>; getChargesByMissingRequiredInfo(): Promise<import("../types.js").IGetChargesByMissingRequiredInfoResult[]>; updateCharge(params: IUpdateChargeParams): Promise<import("../types.js").IUpdateChargeResult>; batchUpdateCharges(params: IBatchUpdateChargesParams): Promise<import("../types.js").IBatchUpdateChargesResult[]>; updateAccountantApproval(params: IUpdateAccountantApprovalParams): Promise<import("../types.js").IUpdateAccountantApprovalResult>; generateCharge(params: IGenerateChargeParams, dbConnection?: IDatabaseConnection): Promise<import("../types.js").IGenerateChargeResult>; getChargesByFilters(params: IGetAdjustedChargesByFiltersParams): Promise<IGetChargesByFiltersResult[]>; getSimilarCharges(params: IGetSimilarChargesParams): Promise<IGetChargesByFiltersResult[]>; deleteChargesByIds(params: IDeleteChargesByIdsParams): Promise<void[]>; deleteCharge(chargeId: string): Promise<void[]>; invalidateCharge(chargeId: string): Promise<void>; clearCache(): void; } export {};