mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
refactor(nestjs): hook the new endpoints
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
import { BillPaymentsApplication } from './BillPaymentsApplication.service';
|
||||
import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
|
||||
@@ -13,6 +14,7 @@ import {
|
||||
CreateBillPaymentDto,
|
||||
EditBillPaymentDto,
|
||||
} from './dtos/BillPayment.dto';
|
||||
import { GetBillPaymentsFilterDto } from './dtos/GetBillPaymentsFilter.dto';
|
||||
|
||||
@Controller('bill-payments')
|
||||
@ApiTags('bill-payments')
|
||||
@@ -57,6 +59,18 @@ export class BillPaymentsController {
|
||||
);
|
||||
}
|
||||
|
||||
@Get(':billPaymentId/bills')
|
||||
@ApiOperation({ summary: 'Retrieves the bills of the given bill payment.' })
|
||||
@ApiParam({
|
||||
name: 'billPaymentId',
|
||||
required: true,
|
||||
type: Number,
|
||||
description: 'The bill payment id',
|
||||
})
|
||||
public getPaymentBills(@Param('billPaymentId') billPaymentId: string) {
|
||||
return this.billPaymentsApplication.getPaymentBills(Number(billPaymentId));
|
||||
}
|
||||
|
||||
@Get(':billPaymentId')
|
||||
@ApiOperation({ summary: 'Retrieves the bill payment details.' })
|
||||
@ApiParam({
|
||||
@@ -69,15 +83,9 @@ export class BillPaymentsController {
|
||||
return this.billPaymentsApplication.getBillPayment(Number(billPaymentId));
|
||||
}
|
||||
|
||||
@Get(':billPaymentId/bills')
|
||||
@ApiOperation({ summary: 'Retrieves the bills of the given bill payment.' })
|
||||
@ApiParam({
|
||||
name: 'billPaymentId',
|
||||
required: true,
|
||||
type: Number,
|
||||
description: 'The bill payment id',
|
||||
})
|
||||
public getPaymentBills(@Param('billPaymentId') billPaymentId: string) {
|
||||
return this.billPaymentsApplication.getPaymentBills(Number(billPaymentId));
|
||||
@Get('')
|
||||
@ApiOperation({ summary: 'Retrieves the bill payments list.' })
|
||||
public getBillPayments(@Query() filterDTO: GetBillPaymentsFilterDto) {
|
||||
return this.billPaymentsApplication.getBillPayments(filterDTO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,12 @@ import { BillPaymentGLEntriesSubscriber } from './subscribers/BillPaymentGLEntri
|
||||
import { LedgerModule } from '../Ledger/Ledger.module';
|
||||
import { AccountsModule } from '../Accounts/Accounts.module';
|
||||
import { BillPaymentsExportable } from './queries/BillPaymentsExportable';
|
||||
import { GetBillPayments } from '../Bills/queries/GetBillPayments';
|
||||
import { BillPaymentsImportable } from './commands/BillPaymentsImportable';
|
||||
import { GetBillPaymentsService } from './queries/GetBillPayments.service';
|
||||
import { DynamicListModule } from '../DynamicListing/DynamicList.module';
|
||||
|
||||
@Module({
|
||||
imports: [LedgerModule, AccountsModule],
|
||||
imports: [LedgerModule, AccountsModule, DynamicListModule],
|
||||
providers: [
|
||||
BillPaymentsApplication,
|
||||
CreateBillPaymentService,
|
||||
@@ -37,9 +38,9 @@ import { BillPaymentsImportable } from './commands/BillPaymentsImportable';
|
||||
TenancyContext,
|
||||
BillPaymentGLEntries,
|
||||
BillPaymentGLEntriesSubscriber,
|
||||
GetBillPayments,
|
||||
BillPaymentsExportable,
|
||||
BillPaymentsImportable,
|
||||
GetBillPaymentsService,
|
||||
],
|
||||
exports: [
|
||||
BillPaymentValidators,
|
||||
|
||||
@@ -2,11 +2,11 @@ import { Injectable } from '@nestjs/common';
|
||||
import { CreateBillPaymentService } from './commands/CreateBillPayment.service';
|
||||
import { DeleteBillPayment } from './commands/DeleteBillPayment.service';
|
||||
import { EditBillPayment } from './commands/EditBillPayment.service';
|
||||
// import { GetBillPayments } from './GetBillPayments';
|
||||
import { GetBillPayment } from './queries/GetBillPayment.service';
|
||||
import { GetPaymentBills } from './queries/GetPaymentBills.service';
|
||||
import { GetBillPayments } from '../Bills/queries/GetBillPayments';
|
||||
import { CreateBillPaymentDto, EditBillPaymentDto } from './dtos/BillPayment.dto';
|
||||
import { GetBillPaymentsService } from './queries/GetBillPayments.service';
|
||||
import { GetBillPaymentsFilterDto } from './dtos/GetBillPaymentsFilter.dto';
|
||||
|
||||
/**
|
||||
* Bill payments application.
|
||||
@@ -20,7 +20,7 @@ export class BillPaymentsApplication {
|
||||
private deleteBillPaymentService: DeleteBillPayment,
|
||||
private getBillPaymentService: GetBillPayment,
|
||||
private getPaymentBillsService: GetPaymentBills,
|
||||
private getBillPaymentsService: GetBillPayments,
|
||||
private getBillPaymentsService: GetBillPaymentsService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -58,9 +58,10 @@ export class BillPaymentsApplication {
|
||||
|
||||
/**
|
||||
* Retrieves bill payments list.
|
||||
* @param {GetBillPaymentsFilterDto} filterDTO - The given bill payments filter dto.
|
||||
*/
|
||||
public getBillPayments() {
|
||||
// return this.getBillPaymentsService.getBillPayments(filterDTO);
|
||||
public getBillPayments(filterDTO: GetBillPaymentsFilterDto) {
|
||||
return this.getBillPaymentsService.getBillPayments(filterDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import * as R from 'ramda';
|
||||
// import {
|
||||
// IBillPayment,
|
||||
// IBillPaymentsFilter,
|
||||
// IPaginationMeta,
|
||||
// IFilterMeta,
|
||||
// } from '@/interfaces';
|
||||
// import { BillPaymentTransformer } from './queries/BillPaymentTransformer';
|
||||
// import DynamicListingService from '@/services/DynamicListing/DynamicListService';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||
|
||||
// @Service()
|
||||
// export class GetBillPayments {
|
||||
// @Inject()
|
||||
// private tenancy: HasTenancyService;
|
||||
|
||||
// @Inject()
|
||||
// private dynamicListService: DynamicListingService;
|
||||
|
||||
// @Inject()
|
||||
// private transformer: TransformerInjectable;
|
||||
|
||||
// /**
|
||||
// * Retrieve bill payment paginted and filterable list.
|
||||
// * @param {number} tenantId
|
||||
// * @param {IBillPaymentsFilter} billPaymentsFilter
|
||||
// */
|
||||
// public async getBillPayments(
|
||||
// tenantId: number,
|
||||
// filterDTO: IBillPaymentsFilter
|
||||
// ): Promise<{
|
||||
// billPayments: IBillPayment[];
|
||||
// pagination: IPaginationMeta;
|
||||
// filterMeta: IFilterMeta;
|
||||
// }> {
|
||||
// const { BillPayment } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Parses filter DTO.
|
||||
// const filter = this.parseListFilterDTO(filterDTO);
|
||||
|
||||
// // Dynamic list service.
|
||||
// const dynamicList = await this.dynamicListService.dynamicList(
|
||||
// tenantId,
|
||||
// BillPayment,
|
||||
// filter
|
||||
// );
|
||||
// const { results, pagination } = await BillPayment.query()
|
||||
// .onBuild((builder) => {
|
||||
// builder.withGraphFetched('vendor');
|
||||
// builder.withGraphFetched('paymentAccount');
|
||||
|
||||
// dynamicList.buildQuery()(builder);
|
||||
// filter?.filterQuery && filter?.filterQuery(builder);
|
||||
// })
|
||||
// .pagination(filter.page - 1, filter.pageSize);
|
||||
|
||||
// // Transformes the bill payments models to POJO.
|
||||
// const billPayments = await this.transformer.transform(
|
||||
// tenantId,
|
||||
// results,
|
||||
// new BillPaymentTransformer()
|
||||
// );
|
||||
// return {
|
||||
// billPayments,
|
||||
// pagination,
|
||||
// filterMeta: dynamicList.getResponseMeta(),
|
||||
// };
|
||||
// }
|
||||
|
||||
// private parseListFilterDTO(filterDTO) {
|
||||
// return R.compose(this.dynamicListService.parseStringifiedFilter)(filterDTO);
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsIn, IsJSON, IsNumber, IsOptional, IsString } from 'class-validator';
|
||||
|
||||
export class GetBillPaymentsFilterDto {
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Type(() => Number)
|
||||
readonly customViewId?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsJSON()
|
||||
readonly stringifiedFilterRoles?: string;
|
||||
|
||||
@IsOptional()
|
||||
readonly columnSortBy?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsIn(['desc', 'asc'])
|
||||
readonly sortOrder?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Type(() => Number)
|
||||
readonly page?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Type(() => Number)
|
||||
readonly pageSize?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
readonly searchKeyword?: string;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { ExportableModel } from '@/modules/Export/decorators/ExportableModel.dec
|
||||
import { InjectModelMeta } from '@/modules/Tenancy/TenancyModels/decorators/InjectModelMeta.decorator';
|
||||
import { BillPaymentMeta } from './BillPayment.meta';
|
||||
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';
|
||||
import { Model } from 'objection';
|
||||
|
||||
@ImportableModel()
|
||||
@ExportableModel()
|
||||
@@ -60,103 +61,98 @@ export class BillPayment extends TenantBaseModel {
|
||||
get localAmount() {
|
||||
return this.amount * this.exchangeRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model settings.
|
||||
*/
|
||||
// static get meta() {
|
||||
// return BillPaymentSettings;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
// static get relationMappings() {
|
||||
// const BillPaymentEntry = require('models/BillPaymentEntry');
|
||||
// const AccountTransaction = require('models/AccountTransaction');
|
||||
// const Vendor = require('models/Vendor');
|
||||
// const Account = require('models/Account');
|
||||
// const Branch = require('models/Branch');
|
||||
// const Document = require('models/Document');
|
||||
static get relationMappings() {
|
||||
const { BillPaymentEntry } = require('./BillPaymentEntry');
|
||||
const {
|
||||
AccountTransaction,
|
||||
} = require('../../Accounts/models/AccountTransaction.model');
|
||||
const { Vendor } = require('../../Vendors/models/Vendor');
|
||||
const { Account } = require('../../Accounts/models/Account.model');
|
||||
const { Branch } = require('../../Branches/models/Branch.model');
|
||||
const { Document } = require('../../ChromiumlyTenancy/models/Document');
|
||||
|
||||
// return {
|
||||
// entries: {
|
||||
// relation: Model.HasManyRelation,
|
||||
// modelClass: BillPaymentEntry.default,
|
||||
// join: {
|
||||
// from: 'bills_payments.id',
|
||||
// to: 'bills_payments_entries.billPaymentId',
|
||||
// },
|
||||
// filter: (query) => {
|
||||
// query.orderBy('index', 'ASC');
|
||||
// },
|
||||
// },
|
||||
return {
|
||||
entries: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: BillPaymentEntry,
|
||||
join: {
|
||||
from: 'bills_payments.id',
|
||||
to: 'bills_payments_entries.billPaymentId',
|
||||
},
|
||||
filter: (query) => {
|
||||
query.orderBy('index', 'ASC');
|
||||
},
|
||||
},
|
||||
|
||||
// vendor: {
|
||||
// relation: Model.BelongsToOneRelation,
|
||||
// modelClass: Vendor.default,
|
||||
// join: {
|
||||
// from: 'bills_payments.vendorId',
|
||||
// to: 'contacts.id',
|
||||
// },
|
||||
// filter(query) {
|
||||
// query.where('contact_service', 'vendor');
|
||||
// },
|
||||
// },
|
||||
vendor: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Vendor,
|
||||
join: {
|
||||
from: 'bills_payments.vendorId',
|
||||
to: 'contacts.id',
|
||||
},
|
||||
filter(query) {
|
||||
query.where('contact_service', 'vendor');
|
||||
},
|
||||
},
|
||||
|
||||
// paymentAccount: {
|
||||
// relation: Model.BelongsToOneRelation,
|
||||
// modelClass: Account.default,
|
||||
// join: {
|
||||
// from: 'bills_payments.paymentAccountId',
|
||||
// to: 'accounts.id',
|
||||
// },
|
||||
// },
|
||||
paymentAccount: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Account,
|
||||
join: {
|
||||
from: 'bills_payments.paymentAccountId',
|
||||
to: 'accounts.id',
|
||||
},
|
||||
},
|
||||
|
||||
// transactions: {
|
||||
// relation: Model.HasManyRelation,
|
||||
// modelClass: AccountTransaction.default,
|
||||
// join: {
|
||||
// from: 'bills_payments.id',
|
||||
// to: 'accounts_transactions.referenceId',
|
||||
// },
|
||||
// filter(builder) {
|
||||
// builder.where('reference_type', 'BillPayment');
|
||||
// },
|
||||
// },
|
||||
transactions: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: AccountTransaction,
|
||||
join: {
|
||||
from: 'bills_payments.id',
|
||||
to: 'accounts_transactions.referenceId',
|
||||
},
|
||||
filter(builder) {
|
||||
builder.where('reference_type', 'BillPayment');
|
||||
},
|
||||
},
|
||||
|
||||
// /**
|
||||
// * Bill payment may belongs to branch.
|
||||
// */
|
||||
// branch: {
|
||||
// relation: Model.BelongsToOneRelation,
|
||||
// modelClass: Branch.default,
|
||||
// join: {
|
||||
// from: 'bills_payments.branchId',
|
||||
// to: 'branches.id',
|
||||
// },
|
||||
// },
|
||||
/**
|
||||
* Bill payment may belongs to branch.
|
||||
*/
|
||||
branch: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Branch,
|
||||
join: {
|
||||
from: 'bills_payments.branchId',
|
||||
to: 'branches.id',
|
||||
},
|
||||
},
|
||||
|
||||
// /**
|
||||
// * Bill payment may has many attached attachments.
|
||||
// */
|
||||
// attachments: {
|
||||
// relation: Model.ManyToManyRelation,
|
||||
// modelClass: Document.default,
|
||||
// join: {
|
||||
// from: 'bills_payments.id',
|
||||
// through: {
|
||||
// from: 'document_links.modelId',
|
||||
// to: 'document_links.documentId',
|
||||
// },
|
||||
// to: 'documents.id',
|
||||
// },
|
||||
// filter(query) {
|
||||
// query.where('model_ref', 'BillPayment');
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
// }
|
||||
/**
|
||||
* Bill payment may has many attached attachments.
|
||||
*/
|
||||
attachments: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: Document,
|
||||
join: {
|
||||
from: 'bills_payments.id',
|
||||
through: {
|
||||
from: 'document_links.modelId',
|
||||
to: 'document_links.documentId',
|
||||
},
|
||||
to: 'documents.id',
|
||||
},
|
||||
filter(query) {
|
||||
query.where('model_ref', 'BillPayment');
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the default custom views, roles and columns.
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { BillPaymentsApplication } from "../BillPaymentsApplication.service";
|
||||
import { Exportable } from "@/modules/Export/Exportable";
|
||||
import { EXPORT_SIZE_LIMIT } from "@/modules/Export/constants";
|
||||
import { ExportableService } from "@/modules/Export/decorators/ExportableModel.decorator";
|
||||
import { BillPayment } from "../models/BillPayment";
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { BillPaymentsApplication } from '../BillPaymentsApplication.service';
|
||||
import { Exportable } from '@/modules/Export/Exportable';
|
||||
import { EXPORT_SIZE_LIMIT } from '@/modules/Export/constants';
|
||||
import { ExportableService } from '@/modules/Export/decorators/ExportableModel.decorator';
|
||||
import { BillPayment } from '../models/BillPayment';
|
||||
|
||||
@Injectable()
|
||||
@ExportableService({ name: BillPayment.name })
|
||||
export class BillPaymentsExportable extends Exportable {
|
||||
constructor(
|
||||
private readonly billPaymentsApplication: BillPaymentsApplication
|
||||
private readonly billPaymentsApplication: BillPaymentsApplication,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@@ -30,13 +30,11 @@ export class BillPaymentsExportable extends Exportable {
|
||||
...query,
|
||||
page: 1,
|
||||
pageSize: EXPORT_SIZE_LIMIT,
|
||||
filterQuery
|
||||
filterQuery,
|
||||
} as any;
|
||||
|
||||
return [];
|
||||
|
||||
// return this.billPaymentsApplication
|
||||
// .billPayments(tenantId, parsedQuery)
|
||||
// .then((output) => output.billPayments);
|
||||
return this.billPaymentsApplication
|
||||
.getBillPayments(parsedQuery)
|
||||
.then((output) => output.billPayments);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import * as R from 'ramda';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { BillPayment } from '../models/BillPayment';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
|
||||
import { DynamicListService } from '@/modules/DynamicListing/DynamicList.service';
|
||||
import { BillPaymentTransformer } from './BillPaymentTransformer';
|
||||
import { GetBillPaymentsFilterDto } from '../dtos/GetBillPaymentsFilter.dto';
|
||||
|
||||
@Injectable()
|
||||
export class GetBillPaymentsService {
|
||||
constructor(
|
||||
private readonly dynamicListService: DynamicListService,
|
||||
private readonly transformer: TransformerInjectable,
|
||||
|
||||
@Inject(BillPayment.name)
|
||||
private readonly billPaymentModel: TenantModelProxy<typeof BillPayment>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Retrieve bill payment paginted and filterable list.
|
||||
* @param {GetBillPaymentsFilterDto} billPaymentsFilter
|
||||
*/
|
||||
public async getBillPayments(filterDTO: GetBillPaymentsFilterDto) {
|
||||
const _filterDto = {
|
||||
page: 1,
|
||||
pageSize: 12,
|
||||
filterRoles: [],
|
||||
sortOrder: 'desc',
|
||||
columnSortBy: 'created_at',
|
||||
...filterDTO,
|
||||
};
|
||||
// Parses filter DTO.
|
||||
const filter = this.parseListFilterDTO(_filterDto);
|
||||
|
||||
// Dynamic list service.
|
||||
const dynamicList = await this.dynamicListService.dynamicList(
|
||||
BillPayment,
|
||||
filter,
|
||||
);
|
||||
const { results, pagination } = await this.billPaymentModel()
|
||||
.query()
|
||||
.onBuild((builder) => {
|
||||
builder.withGraphFetched('vendor');
|
||||
builder.withGraphFetched('paymentAccount');
|
||||
|
||||
dynamicList.buildQuery()(builder);
|
||||
filter?.filterQuery && filter?.filterQuery(builder);
|
||||
})
|
||||
.pagination(filter.page - 1, filter.pageSize);
|
||||
|
||||
// Transformes the bill payments models to POJO.
|
||||
const billPayments = await this.transformer.transform(
|
||||
results,
|
||||
new BillPaymentTransformer(),
|
||||
);
|
||||
return {
|
||||
billPayments,
|
||||
pagination,
|
||||
filterMeta: dynamicList.getResponseMeta(),
|
||||
};
|
||||
}
|
||||
|
||||
private parseListFilterDTO(filterDTO) {
|
||||
return R.compose(this.dynamicListService.parseStringifiedFilter)(filterDTO);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ export class BillPaymentGLEntriesSubscriber {
|
||||
* Handle bill payment writing journal entries once created.
|
||||
*/
|
||||
@OnEvent(events.billPayment.onCreated)
|
||||
private async handleWriteJournalEntries({
|
||||
async handleWriteJournalEntries({
|
||||
billPayment,
|
||||
trx,
|
||||
}: IBillPaymentEventCreatedPayload) {
|
||||
@@ -34,7 +34,7 @@ export class BillPaymentGLEntriesSubscriber {
|
||||
* Handle bill payment re-writing journal entries once the payment transaction be edited.
|
||||
*/
|
||||
@OnEvent(events.billPayment.onEdited)
|
||||
private async handleRewriteJournalEntriesOncePaymentEdited({
|
||||
async handleRewriteJournalEntriesOncePaymentEdited({
|
||||
billPayment,
|
||||
trx,
|
||||
}: IBillPaymentEventEditedPayload) {
|
||||
@@ -48,7 +48,7 @@ export class BillPaymentGLEntriesSubscriber {
|
||||
* Reverts journal entries once bill payment deleted.
|
||||
*/
|
||||
@OnEvent(events.billPayment.onDeleted)
|
||||
private async handleRevertJournalEntries({
|
||||
async handleRevertJournalEntries({
|
||||
billPaymentId,
|
||||
trx,
|
||||
}: IBillPaymentEventDeletedPayload) {
|
||||
|
||||
Reference in New Issue
Block a user