diff --git a/modules/core/src/common/dto/critera.dto.ts b/modules/core/src/common/dto/critera.dto.ts index 22a289ca..516c3438 100644 --- a/modules/core/src/common/dto/critera.dto.ts +++ b/modules/core/src/common/dto/critera.dto.ts @@ -12,16 +12,20 @@ export const FilterPrimitiveSchema = z.object({ }); export const CriteriaSchema = z.object({ - filters: z.array(FilterPrimitiveSchema), + filters: z.array(FilterPrimitiveSchema).optional(), // Preferimos omitido; si viene, no puede ser cadena vacía orderBy: z.string().min(1).optional(), - order: z.enum(["asc", "desc"]), + order: z.enum(["asc", "desc"]).optional(), // Ya son números (normalizados); validaciones lógicas - pageSize: z.number().int().min(1, { message: "pageSize must be a positive integer" }), - pageNumber: z.number().int().min(0, { message: "pageNumber must be a non-negative integer" }), + pageSize: z.number().int().min(1, { message: "pageSize must be a positive integer" }).optional(), + pageNumber: z + .number() + .int() + .min(0, { message: "pageNumber must be a non-negative integer" }) + .optional(), }); export type CriteriaDTO = z.infer; diff --git a/modules/customers/src/api/application/get-customer/assembler/get-customer.assembler.ts b/modules/customers/src/api/application/get-customer/assembler/get-customer.assembler.ts index bf0ed945..171377bc 100644 --- a/modules/customers/src/api/application/get-customer/assembler/get-customer.assembler.ts +++ b/modules/customers/src/api/application/get-customer/assembler/get-customer.assembler.ts @@ -7,9 +7,9 @@ export class GetCustomerAssembler { id: customer.id.toPrimitive(), reference: customer.reference, - is_companyr: customer.isFreelancer, + is_company: customer.isCompany, name: customer.name, - trade_name: customer.tradeName.getOrUndefined(), + trade_name: customer.tradeName ?? "", tin: customer.tin.toPrimitive(), metadata: { diff --git a/modules/customers/src/api/application/list-customers/assembler/list-customers.assembler.ts b/modules/customers/src/api/application/list-customers/assembler/list-customers.assembler.ts index 62ef2f33..fa914f0a 100644 --- a/modules/customers/src/api/application/list-customers/assembler/list-customers.assembler.ts +++ b/modules/customers/src/api/application/list-customers/assembler/list-customers.assembler.ts @@ -12,10 +12,10 @@ export class ListCustomersAssembler { id: customer.id.toPrimitive(), reference: customer.reference, - is_companyr: customer.isFreelancer, + is_company: customer.isCompany, name: customer.name, - trade_name: customer.tradeName.getOrUndefined() || "", - tin: customer.tin.toString(), + trade_name: customer.tradeName ?? "", + tin: customer.tin.toPrimitive(), street: address.street, city: address.city, @@ -23,10 +23,10 @@ export class ListCustomersAssembler { postal_code: address.postalCode, country: address.country, - email: customer.email.getValue(), - phone: customer.phone.getValue(), - fax: customer.fax.isSome() ? customer.fax.getOrUndefined()!.getValue() : "", - website: customer.website.getOrUndefined() || "", + email: customer.email.toPrimitive(), + phone: customer.phone.toPrimitive(), + fax: customer.fax.toPrimitive(), + website: customer.website ?? "", legal_record: customer.legalRecord, diff --git a/modules/customers/src/api/application/list-customers/list-customers.use-case.ts b/modules/customers/src/api/application/list-customers/list-customers.use-case.ts index 85edc8d0..371c00bd 100644 --- a/modules/customers/src/api/application/list-customers/list-customers.use-case.ts +++ b/modules/customers/src/api/application/list-customers/list-customers.use-case.ts @@ -7,7 +7,7 @@ import { ICustomerService } from "../../domain"; import { ListCustomersAssembler } from "./assembler"; type ListCustomersUseCaseInput = { - tenantId: string; + companyId: UniqueID; criteria: Criteria; }; @@ -21,11 +21,15 @@ export class ListCustomersUseCase { public execute( params: ListCustomersUseCaseInput ): Promise> { - const { criteria, tenantId } = params; + const { criteria, companyId } = params; return this.transactionManager.complete(async (transaction: Transaction) => { try { - const result = await this.customerService.findByCriteria(criteria, transaction); + const result = await this.customerService.findCustomerByCriteriaInCompany( + companyId, + criteria, + transaction + ); if (result.isFailure) { return Result.fail(result.error); diff --git a/modules/customers/src/api/infrastructure/express/controllers/list-customers.controller.ts b/modules/customers/src/api/infrastructure/express/controllers/list-customers.controller.ts index 1bf2c364..06c66c62 100644 --- a/modules/customers/src/api/infrastructure/express/controllers/list-customers.controller.ts +++ b/modules/customers/src/api/infrastructure/express/controllers/list-customers.controller.ts @@ -9,8 +9,8 @@ export class ListCustomersController extends ExpressController { } protected async executeImpl() { - const tenantId = this.getTenantId()!; // garantizado por tenantGuard - const result = await this.listCustomers.execute({ criteria: this.criteria, tenantId }); + const companyId = this.getTenantId()!; // garantizado por tenantGuard + const result = await this.listCustomers.execute({ criteria: this.criteria, companyId }); return result.match( (data) => this.ok(data), diff --git a/modules/customers/src/common/dto/response/customer-list.response.dto.ts b/modules/customers/src/common/dto/response/customer-list.response.dto.ts index 63985c79..fead2130 100644 --- a/modules/customers/src/common/dto/response/customer-list.response.dto.ts +++ b/modules/customers/src/common/dto/response/customer-list.response.dto.ts @@ -6,7 +6,7 @@ export const CustomerListResponseSchema = createListViewResponseSchema( id: z.uuid(), reference: z.string(), - is_companyr: z.boolean(), + is_company: z.boolean(), name: z.string(), trade_name: z.string(), tin: z.string(), diff --git a/modules/customers/src/common/dto/response/get-customer-by-id.response.dto.ts b/modules/customers/src/common/dto/response/get-customer-by-id.response.dto.ts index 5c858b8b..3743a8bb 100644 --- a/modules/customers/src/common/dto/response/get-customer-by-id.response.dto.ts +++ b/modules/customers/src/common/dto/response/get-customer-by-id.response.dto.ts @@ -5,7 +5,7 @@ export const GetCustomerByIdResponseSchema = z.object({ id: z.uuid(), reference: z.string(), - is_companyr: z.boolean(), + is_company: z.boolean(), name: z.string(), trade_name: z.string(), tin: z.string(),