Clientes
This commit is contained in:
parent
6101309886
commit
4a36097290
@ -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<typeof CriteriaSchema>;
|
||||
|
||||
@ -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: {
|
||||
|
||||
@ -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,
|
||||
|
||||
|
||||
@ -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<Result<CustomerListResponsetDTO, Error>> {
|
||||
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);
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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(),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user