Compare commits

..

No commits in common. "4a3609729003d109d567c132b55742a9e934cd81" and "f53f71760bd58df1ddbdfadea53c609c5394648d" have entirely different histories.

8 changed files with 21 additions and 29 deletions

View File

@ -1,3 +1,3 @@
{ {
"recommendations": ["biomejs.biome", "cweijan.vscode-mysql-client2"] "recommendations": ["biomejs.biome"]
} }

View File

@ -12,20 +12,16 @@ export const FilterPrimitiveSchema = z.object({
}); });
export const CriteriaSchema = z.object({ export const CriteriaSchema = z.object({
filters: z.array(FilterPrimitiveSchema).optional(), filters: z.array(FilterPrimitiveSchema),
// Preferimos omitido; si viene, no puede ser cadena vacía // Preferimos omitido; si viene, no puede ser cadena vacía
orderBy: z.string().min(1).optional(), orderBy: z.string().min(1).optional(),
order: z.enum(["asc", "desc"]).optional(), order: z.enum(["asc", "desc"]),
// Ya son números (normalizados); validaciones lógicas // Ya son números (normalizados); validaciones lógicas
pageSize: z.number().int().min(1, { message: "pageSize must be a positive integer" }).optional(), pageSize: z.number().int().min(1, { message: "pageSize must be a positive integer" }),
pageNumber: z pageNumber: z.number().int().min(0, { message: "pageNumber must be a non-negative integer" }),
.number()
.int()
.min(0, { message: "pageNumber must be a non-negative integer" })
.optional(),
}); });
export type CriteriaDTO = z.infer<typeof CriteriaSchema>; export type CriteriaDTO = z.infer<typeof CriteriaSchema>;

View File

@ -7,9 +7,9 @@ export class GetCustomerAssembler {
id: customer.id.toPrimitive(), id: customer.id.toPrimitive(),
reference: customer.reference, reference: customer.reference,
is_company: customer.isCompany, is_companyr: customer.isFreelancer,
name: customer.name, name: customer.name,
trade_name: customer.tradeName ?? "", trade_name: customer.tradeName.getOrUndefined(),
tin: customer.tin.toPrimitive(), tin: customer.tin.toPrimitive(),
metadata: { metadata: {

View File

@ -12,10 +12,10 @@ export class ListCustomersAssembler {
id: customer.id.toPrimitive(), id: customer.id.toPrimitive(),
reference: customer.reference, reference: customer.reference,
is_company: customer.isCompany, is_companyr: customer.isFreelancer,
name: customer.name, name: customer.name,
trade_name: customer.tradeName ?? "", trade_name: customer.tradeName.getOrUndefined() || "",
tin: customer.tin.toPrimitive(), tin: customer.tin.toString(),
street: address.street, street: address.street,
city: address.city, city: address.city,
@ -23,10 +23,10 @@ export class ListCustomersAssembler {
postal_code: address.postalCode, postal_code: address.postalCode,
country: address.country, country: address.country,
email: customer.email.toPrimitive(), email: customer.email.getValue(),
phone: customer.phone.toPrimitive(), phone: customer.phone.getValue(),
fax: customer.fax.toPrimitive(), fax: customer.fax.isSome() ? customer.fax.getOrUndefined()!.getValue() : "",
website: customer.website ?? "", website: customer.website.getOrUndefined() || "",
legal_record: customer.legalRecord, legal_record: customer.legalRecord,

View File

@ -7,7 +7,7 @@ import { ICustomerService } from "../../domain";
import { ListCustomersAssembler } from "./assembler"; import { ListCustomersAssembler } from "./assembler";
type ListCustomersUseCaseInput = { type ListCustomersUseCaseInput = {
companyId: UniqueID; tenantId: string;
criteria: Criteria; criteria: Criteria;
}; };
@ -21,15 +21,11 @@ export class ListCustomersUseCase {
public execute( public execute(
params: ListCustomersUseCaseInput params: ListCustomersUseCaseInput
): Promise<Result<CustomerListResponsetDTO, Error>> { ): Promise<Result<CustomerListResponsetDTO, Error>> {
const { criteria, companyId } = params; const { criteria, tenantId } = params;
return this.transactionManager.complete(async (transaction: Transaction) => { return this.transactionManager.complete(async (transaction: Transaction) => {
try { try {
const result = await this.customerService.findCustomerByCriteriaInCompany( const result = await this.customerService.findByCriteria(criteria, transaction);
companyId,
criteria,
transaction
);
if (result.isFailure) { if (result.isFailure) {
return Result.fail(result.error); return Result.fail(result.error);

View File

@ -9,8 +9,8 @@ export class ListCustomersController extends ExpressController {
} }
protected async executeImpl() { protected async executeImpl() {
const companyId = this.getTenantId()!; // garantizado por tenantGuard const tenantId = this.getTenantId()!; // garantizado por tenantGuard
const result = await this.listCustomers.execute({ criteria: this.criteria, companyId }); const result = await this.listCustomers.execute({ criteria: this.criteria, tenantId });
return result.match( return result.match(
(data) => this.ok(data), (data) => this.ok(data),

View File

@ -6,7 +6,7 @@ export const CustomerListResponseSchema = createListViewResponseSchema(
id: z.uuid(), id: z.uuid(),
reference: z.string(), reference: z.string(),
is_company: z.boolean(), is_companyr: z.boolean(),
name: z.string(), name: z.string(),
trade_name: z.string(), trade_name: z.string(),
tin: z.string(), tin: z.string(),

View File

@ -5,7 +5,7 @@ export const GetCustomerByIdResponseSchema = z.object({
id: z.uuid(), id: z.uuid(),
reference: z.string(), reference: z.string(),
is_company: z.boolean(), is_companyr: z.boolean(),
name: z.string(), name: z.string(),
trade_name: z.string(), trade_name: z.string(),
tin: z.string(), tin: z.string(),