mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
fix: adjust contact balance
This commit is contained in:
@@ -23,6 +23,7 @@ import {
|
||||
import { CreateCustomerDto } from './dtos/CreateCustomer.dto';
|
||||
import { EditCustomerDto } from './dtos/EditCustomer.dto';
|
||||
import { CustomerResponseDto } from './dtos/CustomerResponse.dto';
|
||||
import { GetCustomersQueryDto } from './dtos/GetCustomersQuery.dto';
|
||||
|
||||
@Controller('customers')
|
||||
@ApiTags('Customers')
|
||||
@@ -51,7 +52,7 @@ export class CustomersController {
|
||||
items: { $ref: getSchemaPath(CustomerResponseDto) },
|
||||
},
|
||||
})
|
||||
getCustomers(@Query() filterDTO: Partial<ICustomersFilter>) {
|
||||
getCustomers(@Query() filterDTO: GetCustomersQueryDto) {
|
||||
return this.customersApplication.getCustomers(filterDTO);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,14 @@ import { CreateCustomer } from './commands/CreateCustomer.service';
|
||||
import { EditCustomer } from './commands/EditCustomer.service';
|
||||
import { DeleteCustomer } from './commands/DeleteCustomer.service';
|
||||
import { EditOpeningBalanceCustomer } from './commands/EditOpeningBalanceCustomer.service';
|
||||
import { ICustomerOpeningBalanceEditDTO, ICustomersFilter } from './types/Customers.types';
|
||||
import {
|
||||
ICustomerOpeningBalanceEditDTO,
|
||||
ICustomersFilter,
|
||||
} from './types/Customers.types';
|
||||
import { CreateCustomerDto } from './dtos/CreateCustomer.dto';
|
||||
import { EditCustomerDto } from './dtos/EditCustomer.dto';
|
||||
import { GetCustomers } from './queries/GetCustomers.service';
|
||||
import { GetCustomersQueryDto } from './dtos/GetCustomersQuery.dto';
|
||||
|
||||
@Injectable()
|
||||
export class CustomersApplication {
|
||||
@@ -76,7 +80,7 @@ export class CustomersApplication {
|
||||
* Retrieve customers paginated list.
|
||||
* @param {ICustomersFilter} filter - Cusotmers filter.
|
||||
*/
|
||||
public getCustomers = (filterDTO: Partial<ICustomersFilter>) => {
|
||||
public getCustomers = (filterDTO: GetCustomersQueryDto) => {
|
||||
return this.getCustomersService.getCustomersList(filterDTO);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ import {
|
||||
IsEmail,
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsString,
|
||||
} from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { ContactAddressDto } from './ContactAddress.dto';
|
||||
import { IsOptional } from '@/common/decorators/Validators';
|
||||
|
||||
export class CreateCustomerDto extends ContactAddressDto {
|
||||
@ApiProperty({
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { IsInt, IsOptional, IsString, IsBoolean } from 'class-validator';
|
||||
import { ToNumber } from '@/common/decorators/Validators';
|
||||
import { DynamicFilterQueryDto } from '@/modules/DynamicListing/dtos/DynamicFilterQuery.dto';
|
||||
import { parseBoolean } from '@/utils/parse-boolean';
|
||||
import { Transform } from 'class-transformer';
|
||||
|
||||
export class GetCustomersQueryDto extends DynamicFilterQueryDto {
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
stringifiedFilterRoles?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@ToNumber()
|
||||
page?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@ToNumber()
|
||||
pageSize?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Transform(({ value }) => parseBoolean(value, false))
|
||||
inactiveMode?: boolean;
|
||||
}
|
||||
@@ -1,8 +1,27 @@
|
||||
import { Model } from 'objection';
|
||||
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';
|
||||
import { InjectModelMeta } from '@/modules/Tenancy/TenancyModels/decorators/InjectModelMeta.decorator';
|
||||
import { CustomerMeta } from './Customer.meta';
|
||||
import { InjectModelDefaultViews } from '@/modules/Views/decorators/InjectModelDefaultViews.decorator';
|
||||
import { CustomerDefaultViews } from '../constants';
|
||||
import { BaseQueryBuilder } from '@/models/Model';
|
||||
import { Knex } from 'knex';
|
||||
|
||||
export class CustomerQueryBuilder<
|
||||
M extends Model,
|
||||
R = M[],
|
||||
> extends BaseQueryBuilder<M, R> {
|
||||
constructor(...args) {
|
||||
// @ts-ignore
|
||||
super(...args);
|
||||
|
||||
this.onBuild((builder) => {
|
||||
if (builder.isFind() || builder.isDelete() || builder.isUpdate()) {
|
||||
builder.where('contact_service', 'customer');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@InjectModelMeta(CustomerMeta)
|
||||
@InjectModelDefaultViews(CustomerDefaultViews)
|
||||
@@ -54,9 +73,7 @@ export class Customer extends TenantBaseModel {
|
||||
/**
|
||||
* Query builder.
|
||||
*/
|
||||
// static get QueryBuilder() {
|
||||
// return CustomerQueryBuilder;
|
||||
// }
|
||||
static QueryBuilder = CustomerQueryBuilder;
|
||||
|
||||
/**
|
||||
* Table name
|
||||
@@ -152,6 +169,7 @@ export class Customer extends TenantBaseModel {
|
||||
);
|
||||
query.having('countOverdue', '>', 0);
|
||||
},
|
||||
|
||||
/**
|
||||
* Filters the unpaid customers.
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
ICustomersFilter,
|
||||
} from '../types/Customers.types';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { GetCustomersQueryDto } from '../dtos/GetCustomersQuery.dto';
|
||||
|
||||
@Injectable()
|
||||
export class GetCustomers {
|
||||
@@ -29,12 +30,12 @@ export class GetCustomers {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve customers paginated list.
|
||||
* @param {ICustomersFilter} filter - Cusotmers filter.
|
||||
* Retrieves customers paginated list.
|
||||
* @param {GetCustomersQueryDto} filter - Cusotmers filter.
|
||||
* @returns {Promise<GetCustomersResponse>}
|
||||
*/
|
||||
public async getCustomersList(
|
||||
filterDto: Partial<ICustomersFilter>,
|
||||
filterDto: GetCustomersQueryDto,
|
||||
): Promise<GetCustomersResponse> {
|
||||
const _filterDto = {
|
||||
inactiveMode: false,
|
||||
|
||||
Reference in New Issue
Block a user