feat(customers): enhance customer retrieval with filtering options
- Updated `findAll` method in `CustomersController` to accept filtering parameters. - Implemented filtering logic in `CustomersService` to retrieve customers based on type and search query. - Added `PosCustomerFilterDto` for query validation. - Updated customer-related DTOs to make fields optional and added length validation where necessary. - Modified customer-related logic in `sales-invoice-tsp.utils.ts` to accommodate new DTO structure. - Added unique constraints to `customer_individuals` and `customer_legal` tables in the database migration. - Removed commented-out code in `PosMiddleware` for cleaner codebase. - Set default value for `is_default_guild_good` to false in `OwnedGoodsService`.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { SaleInvoiceTspAttemptsUpdateInput } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { BadRequestException, NotFoundException } from '@nestjs/common'
|
||||
import {
|
||||
CustomerType,
|
||||
} from '@/generated/prisma/enums'
|
||||
import {
|
||||
Prisma,
|
||||
TspProviderRequestType,
|
||||
@@ -288,11 +291,30 @@ export async function buildCorrectionPayload(
|
||||
invoice.customer && invoice.customer.type !== 'UNKNOWN'
|
||||
? {
|
||||
type: invoice.customer.type,
|
||||
legal_info: invoice.customer.legal ?? undefined,
|
||||
individual_info: invoice.customer.individual ?? undefined,
|
||||
legal_info: invoice.customer.legal
|
||||
? {
|
||||
name: invoice.customer.legal.name ?? undefined,
|
||||
registration_number:
|
||||
invoice.customer.legal.registration_number ?? undefined,
|
||||
postal_code: invoice.customer.legal.postal_code ?? undefined,
|
||||
economic_code: invoice.customer.legal.economic_code ?? undefined,
|
||||
}
|
||||
: undefined,
|
||||
individual_info: invoice.customer.individual
|
||||
? {
|
||||
first_name: invoice.customer.individual.first_name ?? undefined,
|
||||
last_name: invoice.customer.individual.last_name ?? undefined,
|
||||
national_id: invoice.customer.individual.national_id ?? undefined,
|
||||
mobile_number:
|
||||
invoice.customer.individual.mobile_number ?? undefined,
|
||||
postal_code: invoice.customer.individual.postal_code ?? undefined,
|
||||
economic_code:
|
||||
invoice.customer.individual.economic_code ?? undefined,
|
||||
}
|
||||
: undefined,
|
||||
}
|
||||
: {
|
||||
type: 'UNKNOWN',
|
||||
type: CustomerType.UNKNOWN,
|
||||
unknown_info: {
|
||||
name: unknown_customer?.name || '',
|
||||
economic_code: unknown_customer?.economic_code || '',
|
||||
@@ -384,20 +406,8 @@ export async function buildOriginalPayload(
|
||||
customer: {
|
||||
select: {
|
||||
type: true,
|
||||
individual: {
|
||||
select: {
|
||||
first_name: true,
|
||||
last_name: true,
|
||||
national_id: true,
|
||||
mobile_number: true,
|
||||
},
|
||||
},
|
||||
legal: {
|
||||
select: {
|
||||
name: true,
|
||||
economic_code: true,
|
||||
},
|
||||
},
|
||||
individual: true,
|
||||
legal: true,
|
||||
},
|
||||
},
|
||||
payments: {
|
||||
@@ -460,14 +470,33 @@ export async function buildOriginalPayload(
|
||||
},
|
||||
})),
|
||||
customer:
|
||||
invoice.customer && invoice.customer.type !== 'UNKNOWN'
|
||||
invoice.customer && invoice.customer.type !== CustomerType.UNKNOWN
|
||||
? {
|
||||
type: invoice.customer.type,
|
||||
legal_info: invoice.customer.legal ?? undefined,
|
||||
individual_info: invoice.customer.individual ?? undefined,
|
||||
legal_info: invoice.customer.legal
|
||||
? {
|
||||
name: invoice.customer.legal.name ?? undefined,
|
||||
registration_number:
|
||||
invoice.customer.legal.registration_number ?? undefined,
|
||||
postal_code: invoice.customer.legal.postal_code ?? undefined,
|
||||
economic_code: invoice.customer.legal.economic_code ?? undefined,
|
||||
}
|
||||
: undefined,
|
||||
individual_info: invoice.customer.individual
|
||||
? {
|
||||
first_name: invoice.customer.individual.first_name ?? undefined,
|
||||
last_name: invoice.customer.individual.last_name ?? undefined,
|
||||
national_id: invoice.customer.individual.national_id ?? undefined,
|
||||
mobile_number:
|
||||
invoice.customer.individual.mobile_number ?? undefined,
|
||||
postal_code: invoice.customer.individual.postal_code ?? undefined,
|
||||
economic_code:
|
||||
invoice.customer.individual.economic_code ?? undefined,
|
||||
}
|
||||
: undefined,
|
||||
}
|
||||
: {
|
||||
type: 'UNKNOWN',
|
||||
type: CustomerType.UNKNOWN,
|
||||
unknown_info: {
|
||||
name: unknown_customer?.name || '',
|
||||
economic_code: unknown_customer?.economic_code || '',
|
||||
|
||||
Reference in New Issue
Block a user