Clientes
This commit is contained in:
parent
6101309886
commit
4a36097290
@ -12,16 +12,20 @@ export const FilterPrimitiveSchema = z.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const CriteriaSchema = 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
|
// 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"]),
|
order: z.enum(["asc", "desc"]).optional(),
|
||||||
|
|
||||||
// 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" }),
|
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" }),
|
pageNumber: z
|
||||||
|
.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>;
|
||||||
|
|||||||
@ -7,9 +7,9 @@ export class GetCustomerAssembler {
|
|||||||
id: customer.id.toPrimitive(),
|
id: customer.id.toPrimitive(),
|
||||||
reference: customer.reference,
|
reference: customer.reference,
|
||||||
|
|
||||||
is_companyr: customer.isFreelancer,
|
is_company: customer.isCompany,
|
||||||
name: customer.name,
|
name: customer.name,
|
||||||
trade_name: customer.tradeName.getOrUndefined(),
|
trade_name: customer.tradeName ?? "",
|
||||||
tin: customer.tin.toPrimitive(),
|
tin: customer.tin.toPrimitive(),
|
||||||
|
|
||||||
metadata: {
|
metadata: {
|
||||||
|
|||||||
@ -12,10 +12,10 @@ export class ListCustomersAssembler {
|
|||||||
id: customer.id.toPrimitive(),
|
id: customer.id.toPrimitive(),
|
||||||
reference: customer.reference,
|
reference: customer.reference,
|
||||||
|
|
||||||
is_companyr: customer.isFreelancer,
|
is_company: customer.isCompany,
|
||||||
name: customer.name,
|
name: customer.name,
|
||||||
trade_name: customer.tradeName.getOrUndefined() || "",
|
trade_name: customer.tradeName ?? "",
|
||||||
tin: customer.tin.toString(),
|
tin: customer.tin.toPrimitive(),
|
||||||
|
|
||||||
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.getValue(),
|
email: customer.email.toPrimitive(),
|
||||||
phone: customer.phone.getValue(),
|
phone: customer.phone.toPrimitive(),
|
||||||
fax: customer.fax.isSome() ? customer.fax.getOrUndefined()!.getValue() : "",
|
fax: customer.fax.toPrimitive(),
|
||||||
website: customer.website.getOrUndefined() || "",
|
website: customer.website ?? "",
|
||||||
|
|
||||||
legal_record: customer.legalRecord,
|
legal_record: customer.legalRecord,
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { ICustomerService } from "../../domain";
|
|||||||
import { ListCustomersAssembler } from "./assembler";
|
import { ListCustomersAssembler } from "./assembler";
|
||||||
|
|
||||||
type ListCustomersUseCaseInput = {
|
type ListCustomersUseCaseInput = {
|
||||||
tenantId: string;
|
companyId: UniqueID;
|
||||||
criteria: Criteria;
|
criteria: Criteria;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -21,11 +21,15 @@ export class ListCustomersUseCase {
|
|||||||
public execute(
|
public execute(
|
||||||
params: ListCustomersUseCaseInput
|
params: ListCustomersUseCaseInput
|
||||||
): Promise<Result<CustomerListResponsetDTO, Error>> {
|
): Promise<Result<CustomerListResponsetDTO, Error>> {
|
||||||
const { criteria, tenantId } = params;
|
const { criteria, companyId } = params;
|
||||||
|
|
||||||
return this.transactionManager.complete(async (transaction: Transaction) => {
|
return this.transactionManager.complete(async (transaction: Transaction) => {
|
||||||
try {
|
try {
|
||||||
const result = await this.customerService.findByCriteria(criteria, transaction);
|
const result = await this.customerService.findCustomerByCriteriaInCompany(
|
||||||
|
companyId,
|
||||||
|
criteria,
|
||||||
|
transaction
|
||||||
|
);
|
||||||
|
|
||||||
if (result.isFailure) {
|
if (result.isFailure) {
|
||||||
return Result.fail(result.error);
|
return Result.fail(result.error);
|
||||||
|
|||||||
@ -9,8 +9,8 @@ export class ListCustomersController extends ExpressController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async executeImpl() {
|
protected async executeImpl() {
|
||||||
const tenantId = this.getTenantId()!; // garantizado por tenantGuard
|
const companyId = this.getTenantId()!; // garantizado por tenantGuard
|
||||||
const result = await this.listCustomers.execute({ criteria: this.criteria, tenantId });
|
const result = await this.listCustomers.execute({ criteria: this.criteria, companyId });
|
||||||
|
|
||||||
return result.match(
|
return result.match(
|
||||||
(data) => this.ok(data),
|
(data) => this.ok(data),
|
||||||
|
|||||||
@ -6,7 +6,7 @@ export const CustomerListResponseSchema = createListViewResponseSchema(
|
|||||||
id: z.uuid(),
|
id: z.uuid(),
|
||||||
reference: z.string(),
|
reference: z.string(),
|
||||||
|
|
||||||
is_companyr: z.boolean(),
|
is_company: z.boolean(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
trade_name: z.string(),
|
trade_name: z.string(),
|
||||||
tin: z.string(),
|
tin: z.string(),
|
||||||
|
|||||||
@ -5,7 +5,7 @@ export const GetCustomerByIdResponseSchema = z.object({
|
|||||||
id: z.uuid(),
|
id: z.uuid(),
|
||||||
reference: z.string(),
|
reference: z.string(),
|
||||||
|
|
||||||
is_companyr: z.boolean(),
|
is_company: z.boolean(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
trade_name: z.string(),
|
trade_name: z.string(),
|
||||||
tin: z.string(),
|
tin: z.string(),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user