diff --git a/packages/server/src/modules/BankRules/commands/EditBankRule.service.ts b/packages/server/src/modules/BankRules/commands/EditBankRule.service.ts index 8f352cb24..845e82e93 100644 --- a/packages/server/src/modules/BankRules/commands/EditBankRule.service.ts +++ b/packages/server/src/modules/BankRules/commands/EditBankRule.service.ts @@ -23,13 +23,13 @@ export class EditBankRuleService { ) {} /** - * - * @param createDTO + * Transforms the given edit bank rule dto to model object. + * @param editDTO * @returns */ - private transformDTO(createDTO: EditBankRuleDto): ModelObject { + private transformDTO(editDTO: EditBankRuleDto): ModelObject { return { - ...createDTO, + ...editDTO, } as ModelObject; } diff --git a/packages/server/src/modules/BankingCategorize/BankingCategorize.controller.ts b/packages/server/src/modules/BankingCategorize/BankingCategorize.controller.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/server/src/modules/BankingMatching/BankingMatching.controller.ts b/packages/server/src/modules/BankingMatching/BankingMatching.controller.ts index 1c01a53c9..bf95a2f31 100644 --- a/packages/server/src/modules/BankingMatching/BankingMatching.controller.ts +++ b/packages/server/src/modules/BankingMatching/BankingMatching.controller.ts @@ -11,7 +11,7 @@ export class BankingMatchingController { private readonly bankingMatchingApplication: BankingMatchingApplication ) {} - @Get('matched/transactions') + @Get('matched') @ApiOperation({ summary: 'Retrieves the matched transactions.' }) async getMatchedTransactions( @Query('uncategorizedTransactionIds') uncategorizedTransactionIds: number[], diff --git a/packages/server/src/modules/BankingTranasctionsRegonize/BankingRecognizedTransactions.controller.ts b/packages/server/src/modules/BankingTranasctionsRegonize/BankingRecognizedTransactions.controller.ts index 17a2ab8eb..f0627659b 100644 --- a/packages/server/src/modules/BankingTranasctionsRegonize/BankingRecognizedTransactions.controller.ts +++ b/packages/server/src/modules/BankingTranasctionsRegonize/BankingRecognizedTransactions.controller.ts @@ -1,5 +1,4 @@ import { Controller, Get, Param, Query } from '@nestjs/common'; -import { BankingTransactionsApplication } from '../BankingTransactions/BankingTransactionsApplication.service'; import { ApiTags } from '@nestjs/swagger'; import { RecognizedTransactionsApplication } from './RecognizedTransactions.application'; diff --git a/packages/server/src/modules/BankingTranasctionsRegonize/BankingTransactionsRegonize.module.ts b/packages/server/src/modules/BankingTranasctionsRegonize/BankingTransactionsRegonize.module.ts index 9e7fcc10a..4092bee59 100644 --- a/packages/server/src/modules/BankingTranasctionsRegonize/BankingTransactionsRegonize.module.ts +++ b/packages/server/src/modules/BankingTranasctionsRegonize/BankingTransactionsRegonize.module.ts @@ -1,7 +1,6 @@ import { forwardRef, Module } from '@nestjs/common'; import { RegisterTenancyModel } from '../Tenancy/TenancyModels/Tenancy.module'; import { RecognizedBankTransaction } from './models/RecognizedBankTransaction'; -import { GetAutofillCategorizeTransactionService } from './queries/GetAutofillCategorizeTransaction.service'; import { RevertRecognizedTransactionsService } from './commands/RevertRecognizedTransactions.service'; import { RecognizeTranasctionsService } from './commands/RecognizeTranasctions.service'; import { TriggerRecognizedTransactionsSubscriber } from './events/TriggerRecognizedTransactions'; @@ -11,27 +10,34 @@ import { BankingRecognizedTransactionsController } from './BankingRecognizedTran import { RecognizedTransactionsApplication } from './RecognizedTransactions.application'; import { GetRecognizedTransactionsService } from './GetRecongizedTransactions'; import { GetRecognizedTransactionService } from './queries/GetRecognizedTransaction.service'; +import { BullModule } from '@nestjs/bullmq'; +import { RecognizeUncategorizedTransactionsQueue } from './_types'; +import { RegonizeTransactionsPrcessor } from './jobs/RecognizeTransactionsJob'; +import { TenancyModule } from '../Tenancy/Tenancy.module'; const models = [RegisterTenancyModel(RecognizedBankTransaction)]; @Module({ imports: [ BankingTransactionsModule, + TenancyModule, forwardRef(() => BankRulesModule), + BullModule.registerQueue({ + name: RecognizeUncategorizedTransactionsQueue, + }), ...models, ], providers: [ RecognizedTransactionsApplication, GetRecognizedTransactionsService, - GetAutofillCategorizeTransactionService, RevertRecognizedTransactionsService, RecognizeTranasctionsService, TriggerRecognizedTransactionsSubscriber, GetRecognizedTransactionService, + RegonizeTransactionsPrcessor, ], exports: [ ...models, - GetAutofillCategorizeTransactionService, RevertRecognizedTransactionsService, RecognizeTranasctionsService, ], diff --git a/packages/server/src/modules/BankingTranasctionsRegonize/RecognizedTransactions.application.ts b/packages/server/src/modules/BankingTranasctionsRegonize/RecognizedTransactions.application.ts index df9013ca4..a72dcfd62 100644 --- a/packages/server/src/modules/BankingTranasctionsRegonize/RecognizedTransactions.application.ts +++ b/packages/server/src/modules/BankingTranasctionsRegonize/RecognizedTransactions.application.ts @@ -3,7 +3,6 @@ import { Injectable } from '@nestjs/common'; import { GetRecognizedTransactionsService } from './GetRecongizedTransactions'; import { GetRecognizedTransactionService } from './queries/GetRecognizedTransaction.service'; import { RevertRecognizedTransactionsService } from './commands/RevertRecognizedTransactions.service'; -import { GetAutofillCategorizeTransactionService } from './queries/GetAutofillCategorizeTransaction.service'; import { IGetRecognizedTransactionsQuery } from '../BankingTransactions/types/BankingTransactions.types'; import { RevertRecognizedTransactionsCriteria } from './_types'; @@ -13,7 +12,6 @@ export class RecognizedTransactionsApplication { private readonly getRecognizedTransactionsService: GetRecognizedTransactionsService, private readonly getRecognizedTransactionService: GetRecognizedTransactionService, private readonly revertRecognizedTransactionsService: RevertRecognizedTransactionsService, - private readonly getAutofillCategorizeTransactionService: GetAutofillCategorizeTransactionService, ) {} /** @@ -56,15 +54,4 @@ export class RecognizedTransactionsApplication { trx, ); } - - /** - * Gets autofill categorize suggestions for a transaction. - * @param {number} uncategorizedTransactionId - The ID of the uncategorized transaction. - * @returns {Promise} - */ - public getAutofillCategorizeTransaction(uncategorizedTransactionId: number) { - return this.getAutofillCategorizeTransactionService.getAutofillCategorizeTransaction( - uncategorizedTransactionId, - ); - } } diff --git a/packages/server/src/modules/BankingTranasctionsRegonize/_types.ts b/packages/server/src/modules/BankingTranasctionsRegonize/_types.ts index 76ef01b86..71a18e07e 100644 --- a/packages/server/src/modules/BankingTranasctionsRegonize/_types.ts +++ b/packages/server/src/modules/BankingTranasctionsRegonize/_types.ts @@ -1,3 +1,5 @@ +import { TenantJobPayload } from "@/interfaces/Tenant"; + export interface RevertRecognizedTransactionsCriteria { batch?: string; accountId?: number; @@ -7,3 +9,14 @@ export interface RecognizeTransactionsCriteria { batch?: string; accountId?: number; } + +export const RecognizeUncategorizedTransactionsJob = + 'recognize-uncategorized-transactions-job'; +export const RecognizeUncategorizedTransactionsQueue = + 'recognize-uncategorized-transactions-queue'; + + +export interface RecognizeUncategorizedTransactionsJobPayload extends TenantJobPayload { + ruleId: number, + transactionsCriteria: any; +} \ No newline at end of file diff --git a/packages/server/src/modules/BankingTranasctionsRegonize/events/TriggerRecognizedTransactions.ts b/packages/server/src/modules/BankingTranasctionsRegonize/events/TriggerRecognizedTransactions.ts index c6d932648..791d7d8cd 100644 --- a/packages/server/src/modules/BankingTranasctionsRegonize/events/TriggerRecognizedTransactions.ts +++ b/packages/server/src/modules/BankingTranasctionsRegonize/events/TriggerRecognizedTransactions.ts @@ -2,21 +2,47 @@ import { isEqual, omit } from 'lodash'; import { Injectable } from '@nestjs/common'; import { OnEvent } from '@nestjs/event-emitter'; import { events } from '@/common/events/events'; -import { IBankRuleEventCreatedPayload, IBankRuleEventDeletedPayload, IBankRuleEventEditedPayload } from '@/modules/BankRules/types'; +import { + IBankRuleEventCreatedPayload, + IBankRuleEventDeletedPayload, + IBankRuleEventEditedPayload, +} from '@/modules/BankRules/types'; +import { Queue } from 'bullmq'; +import { InjectQueue } from '@nestjs/bullmq'; +import { + RecognizeUncategorizedTransactionsJob, + RecognizeUncategorizedTransactionsJobPayload, + RecognizeUncategorizedTransactionsQueue, +} from '../_types'; +import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service'; @Injectable() export class TriggerRecognizedTransactionsSubscriber { + constructor( + private readonly tenancyContect: TenancyContext, + + @InjectQueue(RecognizeUncategorizedTransactionsQueue) + private readonly recognizeTransactionsQueue: Queue, + ) {} + /** * Triggers the recognize uncategorized transactions job on rule created. * @param {IBankRuleEventCreatedPayload} payload - */ @OnEvent(events.bankRules.onCreated) - private async recognizedTransactionsOnRuleCreated({ + async recognizedTransactionsOnRuleCreated({ bankRule, }: IBankRuleEventCreatedPayload) { - const payload = { ruleId: bankRule.id }; + const tenantPayload = await this.tenancyContect.getTenantJobPayload(); + const payload = { + ruleId: bankRule.id, + ...tenantPayload, + } as RecognizeUncategorizedTransactionsJobPayload; - // await this.agenda.now('recognize-uncategorized-transactions-job', payload); + await this.recognizeTransactionsQueue.add( + RecognizeUncategorizedTransactionsJob, + payload, + ); } /** @@ -29,22 +55,28 @@ export class TriggerRecognizedTransactionsSubscriber { oldBankRule, bankRule, }: IBankRuleEventEditedPayload) { - const payload = { ruleId: bankRule.id }; - + // Cannot continue if the new and old bank rule values are the same, // after excluding `createdAt` and `updatedAt` dates. if ( isEqual( omit(bankRule, ['createdAt', 'updatedAt']), - omit(oldBankRule, ['createdAt', 'updatedAt']) + omit(oldBankRule, ['createdAt', 'updatedAt']), ) ) { return; } - // await this.agenda.now( - // 'rerecognize-uncategorized-transactions-job', - // payload - // ); + const tenantPayload = await this.tenancyContect.getTenantJobPayload(); + const payload = { + ruleId: bankRule.id, + ...tenantPayload, + } as RecognizeUncategorizedTransactionsJobPayload; + + // Re-recognize the transactions based on the new rules. + await this.recognizeTransactionsQueue.add( + RecognizeUncategorizedTransactionsJob, + payload, + ); } /** @@ -52,15 +84,20 @@ export class TriggerRecognizedTransactionsSubscriber { * @param {IBankRuleEventDeletedPayload} payload - */ @OnEvent(events.bankRules.onDeleted) - private async recognizedTransactionsOnRuleDeleted({ + async recognizedTransactionsOnRuleDeleted({ ruleId, }: IBankRuleEventDeletedPayload) { - const payload = { ruleId }; + const tenantPayload = await this.tenancyContect.getTenantJobPayload(); + const payload = { + ruleId, + ...tenantPayload, + } as RecognizeUncategorizedTransactionsJobPayload; - // await this.agenda.now( - // 'revert-recognized-uncategorized-transactions-job', - // payload - // ); + // Re-recognize the transactions based on the new rules. + await this.recognizeTransactionsQueue.add( + RecognizeUncategorizedTransactionsJob, + payload, + ); } /** @@ -68,7 +105,7 @@ export class TriggerRecognizedTransactionsSubscriber { * @param {IImportFileCommitedEventPayload} payload - */ @OnEvent(events.import.onImportCommitted) - private async triggerRecognizeTransactionsOnImportCommitted({ + async triggerRecognizeTransactionsOnImportCommitted({ importId, // @ts-ignore @@ -76,10 +113,8 @@ export class TriggerRecognizedTransactionsSubscriber { // const importFile = await Import.query().findOne({ importId }); // const batch = importFile.paramsParsed.batch; // const payload = { transactionsCriteria: { batch } }; - // // Cannot continue if the imported resource is not bank account transactions. // if (importFile.resource !== 'UncategorizedCashflowTransaction') return; - // await this.agenda.now('recognize-uncategorized-transactions-job', payload); } } diff --git a/packages/server/src/modules/BankingTranasctionsRegonize/jobs/RecognizeTransactionsJob.ts b/packages/server/src/modules/BankingTranasctionsRegonize/jobs/RecognizeTransactionsJob.ts index 3363f49c7..cddd30f81 100644 --- a/packages/server/src/modules/BankingTranasctionsRegonize/jobs/RecognizeTransactionsJob.ts +++ b/packages/server/src/modules/BankingTranasctionsRegonize/jobs/RecognizeTransactionsJob.ts @@ -1,36 +1,48 @@ -// import Container, { Service } from 'typedi'; -// import { RecognizeTranasctionsService } from '../commands/RecognizeTranasctions.service'; +import { Job } from 'bullmq'; +import { Processor, WorkerHost } from '@nestjs/bullmq'; +import { Scope } from '@nestjs/common'; +import { ClsService, UseCls } from 'nestjs-cls'; +import { RecognizeTranasctionsService } from '../commands/RecognizeTranasctions.service'; +import { + RecognizeUncategorizedTransactionsJobPayload, + RecognizeUncategorizedTransactionsQueue, +} from '../_types'; +import { Process } from '@nestjs/bull'; -// @Service() -// export class RegonizeTransactionsJob { -// /** -// * Constructor method. -// */ -// constructor(agenda) { -// agenda.define( -// 'recognize-uncategorized-transactions-job', -// { priority: 'high', concurrency: 2 }, -// this.handler -// ); -// } +@Processor({ + name: RecognizeUncategorizedTransactionsQueue, + scope: Scope.REQUEST, +}) +export class RegonizeTransactionsPrcessor extends WorkerHost { + /** + * @param {RecognizeTranasctionsService} recognizeTranasctionsService - + * @param {ClsService} clsService - + */ + constructor( + private readonly recognizeTranasctionsService: RecognizeTranasctionsService, + private readonly clsService: ClsService, + ) { + super(); + } -// /** -// * Triggers sending invoice mail. -// */ -// private handler = async (job, done: Function) => { -// const { tenantId, ruleId, transactionsCriteria } = job.attrs.data; -// const regonizeTransactions = Container.get(RecognizeTranasctionsService); + /** + * Triggers sending invoice mail. + */ + @Process(RecognizeUncategorizedTransactionsQueue) + @UseCls() + async process(job: Job) { + const { ruleId, transactionsCriteria } = job.data; -// try { -// await regonizeTransactions.recognizeTransactions( -// tenantId, -// ruleId, -// transactionsCriteria -// ); -// done(); -// } catch (error) { -// console.log(error); -// done(error); -// } -// }; -// } + this.clsService.set('organizationId', job.data.organizationId); + this.clsService.set('userId', job.data.userId); + + try { + await this.recognizeTranasctionsService.recognizeTransactions( + ruleId, + transactionsCriteria, + ); + } catch (error) { + console.log(error); + } + } +} diff --git a/packages/server/src/modules/BankingTransactions/BankingTransactions.module.ts b/packages/server/src/modules/BankingTransactions/BankingTransactions.module.ts index d1176a594..b66027e9c 100644 --- a/packages/server/src/modules/BankingTransactions/BankingTransactions.module.ts +++ b/packages/server/src/modules/BankingTransactions/BankingTransactions.module.ts @@ -31,6 +31,7 @@ import { GetUncategorizedBankTransactionService } from './queries/GetUncategoriz import { BankingUncategorizedTransactionsController } from './controllers/BankingUncategorizedTransactions.controller'; import { BankingPendingTransactionsController } from './controllers/BankingPendingTransactions.controller'; import { GetPendingBankAccountTransactions } from './queries/GetPendingBankAccountTransaction.service'; +import { GetAutofillCategorizeTransactionService } from './queries/GetAutofillCategorizeTransaction/GetAutofillCategorizeTransaction.service'; const models = [ RegisterTenancyModel(UncategorizedBankTransaction), @@ -72,7 +73,8 @@ const models = [ GetBankAccountTransactionsService, GetUncategorizedTransactions, GetUncategorizedBankTransactionService, - GetPendingBankAccountTransactions + GetPendingBankAccountTransactions, + GetAutofillCategorizeTransactionService, ], exports: [...models, RemovePendingUncategorizedTransaction], }) diff --git a/packages/server/src/modules/BankingTransactions/BankingTransactionsApplication.service.ts b/packages/server/src/modules/BankingTransactions/BankingTransactionsApplication.service.ts index ccb1cd528..121eba609 100644 --- a/packages/server/src/modules/BankingTransactions/BankingTransactionsApplication.service.ts +++ b/packages/server/src/modules/BankingTransactions/BankingTransactionsApplication.service.ts @@ -14,6 +14,7 @@ import { GetUncategorizedBankTransactionService } from './queries/GetUncategoriz import { GetUncategorizedTransactionsQueryDto } from './dtos/GetUncategorizedTransactionsQuery.dto'; import { GetPendingBankAccountTransactions } from './queries/GetPendingBankAccountTransaction.service'; import { GetPendingTransactionsQueryDto } from './dtos/GetPendingTransactionsQuery.dto'; +import { GetAutofillCategorizeTransactionService } from './queries/GetAutofillCategorizeTransaction/GetAutofillCategorizeTransaction.service'; @Injectable() export class BankingTransactionsApplication { @@ -25,7 +26,8 @@ export class BankingTransactionsApplication { private readonly getBankAccountTransactionsService: GetBankAccountTransactionsService, private readonly getBankAccountUncategorizedTransitionsService: GetUncategorizedTransactions, private readonly getBankAccountUncategorizedTransactionService: GetUncategorizedBankTransactionService, - private readonly getPendingBankAccountTransactionsService: GetPendingBankAccountTransactions + private readonly getPendingBankAccountTransactionsService: GetPendingBankAccountTransactions, + private readonly getAutofillCategorizeTransactionService: GetAutofillCategorizeTransactionService, ) {} /** @@ -106,7 +108,23 @@ export class BankingTransactionsApplication { * Retrieves the pending bank account transactions. * @param {GetPendingTransactionsQueryDto} filter - Pending transactions query. */ - public getPendingBankAccountTransactions(filter?: GetPendingTransactionsQueryDto) { - return this.getPendingBankAccountTransactionsService.getPendingTransactions(filter); + public getPendingBankAccountTransactions( + filter?: GetPendingTransactionsQueryDto, + ) { + return this.getPendingBankAccountTransactionsService.getPendingTransactions( + filter, + ); + } + + /** + * Retrieves the autofill values of categorize transactions form. + * @param {Array | number} uncategorizeTransactionsId - Uncategorized transactions ids. + */ + public getAutofillCategorizeTransaction( + uncategorizeTransactionsId: Array | number, + ) { + return this.getAutofillCategorizeTransactionService.getAutofillCategorizeTransaction( + uncategorizeTransactionsId, + ); } } diff --git a/packages/server/src/modules/BankingTransactions/controllers/BankingUncategorizedTransactions.controller.ts b/packages/server/src/modules/BankingTransactions/controllers/BankingUncategorizedTransactions.controller.ts index 287cbbbd4..dd5789997 100644 --- a/packages/server/src/modules/BankingTransactions/controllers/BankingUncategorizedTransactions.controller.ts +++ b/packages/server/src/modules/BankingTransactions/controllers/BankingUncategorizedTransactions.controller.ts @@ -1,5 +1,11 @@ import { Controller, Get, Param, Query } from '@nestjs/common'; -import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from '@nestjs/swagger'; +import { + ApiTags, + ApiOperation, + ApiResponse, + ApiParam, + ApiQuery, +} from '@nestjs/swagger'; import { GetUncategorizedTransactionsQueryDto } from '../dtos/GetUncategorizedTransactionsQuery.dto'; import { BankingTransactionsApplication } from '../BankingTransactionsApplication.service'; @@ -10,11 +16,41 @@ export class BankingUncategorizedTransactionsController { private readonly bankingTransactionsApplication: BankingTransactionsApplication, ) {} - @Get('accounts/:accountId') - @ApiOperation({ summary: 'Get uncategorized transactions for a specific bank account' }) + @Get('autofill') + @ApiOperation({ summary: 'Get autofill values for categorize transactions' }) @ApiResponse({ status: 200, - description: 'Returns a list of uncategorized transactions for the specified bank account', + description: 'Returns autofill values for categorize transactions', + }) + @ApiParam({ + name: 'accountId', + required: true, + type: Number, + description: 'Bank account ID', + }) + @ApiQuery({ + name: 'uncategorizeTransactionsId', + required: true, + type: Number, + description: 'Uncategorize transactions ID', + }) + async getAutofillCategorizeTransaction( + @Query('uncategorizedTransactionIds') uncategorizedTransactionIds: Array | number, + ) { + console.log(uncategorizedTransactionIds) + return this.bankingTransactionsApplication.getAutofillCategorizeTransaction( + uncategorizedTransactionIds, + ); + } + + @Get('accounts/:accountId') + @ApiOperation({ + summary: 'Get uncategorized transactions for a specific bank account', + }) + @ApiResponse({ + status: 200, + description: + 'Returns a list of uncategorized transactions for the specified bank account', }) @ApiParam({ name: 'accountId', diff --git a/packages/server/src/modules/BankingTranasctionsRegonize/queries/GetAutofillCategorizeTransaction.service.ts b/packages/server/src/modules/BankingTransactions/queries/GetAutofillCategorizeTransaction/GetAutofillCategorizeTransaction.service.ts similarity index 100% rename from packages/server/src/modules/BankingTranasctionsRegonize/queries/GetAutofillCategorizeTransaction.service.ts rename to packages/server/src/modules/BankingTransactions/queries/GetAutofillCategorizeTransaction/GetAutofillCategorizeTransaction.service.ts diff --git a/packages/server/src/modules/BankingTranasctionsRegonize/queries/GetAutofillCategorizeTransactionTransformer.ts b/packages/server/src/modules/BankingTransactions/queries/GetAutofillCategorizeTransaction/GetAutofillCategorizeTransactionTransformer.ts similarity index 100% rename from packages/server/src/modules/BankingTranasctionsRegonize/queries/GetAutofillCategorizeTransactionTransformer.ts rename to packages/server/src/modules/BankingTransactions/queries/GetAutofillCategorizeTransaction/GetAutofillCategorizeTransactionTransformer.ts diff --git a/packages/server/src/modules/BankingTransactionsExclude/BankingTransactionsExclude.controller.ts b/packages/server/src/modules/BankingTransactionsExclude/BankingTransactionsExclude.controller.ts index 0ad68bc44..c75984d32 100644 --- a/packages/server/src/modules/BankingTransactionsExclude/BankingTransactionsExclude.controller.ts +++ b/packages/server/src/modules/BankingTransactionsExclude/BankingTransactionsExclude.controller.ts @@ -5,6 +5,7 @@ import { Get, Param, Post, + Put, Query, } from '@nestjs/common'; import { ExcludeBankTransactionsApplication } from './ExcludeBankTransactionsApplication'; @@ -18,7 +19,7 @@ export class BankingTransactionsExcludeController { private readonly excludeBankTransactionsApplication: ExcludeBankTransactionsApplication, ) {} - @Post('bulk') + @Put('bulk') @ApiOperation({ summary: 'Exclude the given bank transactions.' }) public excludeBankTransactions(@Body('ids') ids: number[]) { return this.excludeBankTransactionsApplication.excludeBankTransactions(ids); @@ -42,7 +43,7 @@ export class BankingTransactionsExcludeController { ); } - @Post(':id') + @Put(':id') @ApiOperation({ summary: 'Exclude the given bank transaction.' }) public excludeBankTransaction(@Param('id') id: string) { return this.excludeBankTransactionsApplication.excludeBankTransaction( diff --git a/packages/server/src/modules/Tenancy/TenancyContext.service.ts b/packages/server/src/modules/Tenancy/TenancyContext.service.ts index 93b35662e..02b13a431 100644 --- a/packages/server/src/modules/Tenancy/TenancyContext.service.ts +++ b/packages/server/src/modules/Tenancy/TenancyContext.service.ts @@ -51,4 +51,14 @@ export class TenancyContext { return this.systemUserModel.query().findById(userId); } + + async getTenantJobPayload() { + const tenant = await this.getTenant(); + const user = await this.getSystemUser(); + + const organizationId = tenant.organizationId; + const userId = user.id; + + return { organizationId, userId }; + } } diff --git a/packages/webapp/src/hooks/query/bank-accounts.ts b/packages/webapp/src/hooks/query/bank-accounts.ts index e5ba6795d..d1716c913 100644 --- a/packages/webapp/src/hooks/query/bank-accounts.ts +++ b/packages/webapp/src/hooks/query/bank-accounts.ts @@ -38,7 +38,7 @@ export function usePauseFeedsBankAccount( >( (values) => apiRequest.post( - `/banking/bank_accounts/${values.bankAccountId}/pause_feeds`, + `/banking/accounts/${values.bankAccountId}/pause`, ), { onSuccess: (res, values) => { diff --git a/packages/webapp/src/hooks/query/bank-rules.ts b/packages/webapp/src/hooks/query/bank-rules.ts index d2633f64d..c4bbcfc8e 100644 --- a/packages/webapp/src/hooks/query/bank-rules.ts +++ b/packages/webapp/src/hooks/query/bank-rules.ts @@ -115,7 +115,7 @@ export function useUpdateBankAccount( return useMutation( ({ bankAccountId }) => - apiRequest.post(`/banking/accounts/${bankAccountId}/update`), + apiRequest.post(`/banking/accounts/${bankAccountId}/refresh`), { ...options, onSuccess: () => {}, @@ -141,7 +141,7 @@ export function useEditBankRule( const apiRequest = useApiRequest(); return useMutation( - ({ id, value }) => apiRequest.post(`/banking/rules/${id}`, value), + ({ id, value }) => apiRequest.put(`/banking/rules/${id}`, value), { ...options, onSuccess: () => { @@ -223,9 +223,7 @@ export function useBankRule( return useQuery( [BANK_QUERY_KEY.BANK_RULES, bankRuleId], () => - apiRequest - .get(`/banking/rules/${bankRuleId}`) - .then((res) => res.data), + apiRequest.get(`/banking/rules/${bankRuleId}`).then((res) => res.data), { ...options }, ); } @@ -245,17 +243,17 @@ interface GetBankTransactionsMatchesResponse { * @returns {UseQueryResult} */ export function useGetBankTransactionsMatches( - uncategorizeTransactionsIds: Array, + uncategorizedTransactionIds: Array, options?: UseQueryOptions, ): UseQueryResult { const apiRequest = useApiRequest(); return useQuery( - [BANK_QUERY_KEY.BANK_TRANSACTION_MATCHES, uncategorizeTransactionsIds], + [BANK_QUERY_KEY.BANK_TRANSACTION_MATCHES, uncategorizedTransactionIds], () => apiRequest .get(`/banking/matching/matched`, { - params: { uncategorizeTransactionsIds }, + params: { uncategorizedTransactionIds }, }) .then((res) => transformToCamelCase(res.data)), options, @@ -311,9 +309,7 @@ export function useExcludeUncategorizedTransaction( ExcludeUncategorizedTransactionValue >( (uncategorizedTransactionId: number) => - apiRequest.put( - `/banking/transactions/${uncategorizedTransactionId}/exclude`, - ), + apiRequest.put(`/banking/exclude/${uncategorizedTransactionId}`), { onSuccess: (res, id) => { onValidateExcludeUncategorizedTransaction(queryClient); @@ -352,9 +348,7 @@ export function useUnexcludeUncategorizedTransaction( ExcludeBankTransactionValue >( (uncategorizedTransactionId: number) => - apiRequest.put( - `/banking/transactions/${uncategorizedTransactionId}/unexclude`, - ), + apiRequest.delete(`/banking/exclude/${uncategorizedTransactionId}`), { onSuccess: (res, id) => { onValidateExcludeUncategorizedTransaction(queryClient); @@ -392,7 +386,7 @@ export function useExcludeUncategorizedTransactions( ExcludeBankTransactionsValue >( (value: { ids: Array }) => - apiRequest.put(`/banking/transactions/exclude`, { ids: value.ids }), + apiRequest.put(`/banking/exclude/bulk`, { ids: value.ids }), { onSuccess: (res, id) => { onValidateExcludeUncategorizedTransaction(queryClient); @@ -430,7 +424,7 @@ export function useUnexcludeUncategorizedTransactions( UnexcludeBankTransactionsValue >( (value: { ids: Array }) => - apiRequest.put(`/banking/transactions/unexclude`, { ids: value.ids }), + apiRequest.delete(`/banking/exclude/bulk`, { ids: value.ids }), { onSuccess: (res, id) => { onValidateExcludeUncategorizedTransaction(queryClient); @@ -613,7 +607,7 @@ export function useGetAutofillCategorizeTransaction( ], () => apiRequest - .get(`/banking/categorize/autofill`, { + .get(`/banking/uncategorized/autofill`, { params: { uncategorizedTransactionIds }, }) .then((res) => transformToCamelCase(res.data)),