Facturas de cliente
This commit is contained in:
parent
5879220fe9
commit
fa56473a00
@ -1,4 +1,3 @@
|
||||
import { JsonTaxCatalogProvider } from "@erp/core";
|
||||
import { ITransactionManager } from "@erp/core/api";
|
||||
import { Criteria } from "@repo/rdx-criteria/server";
|
||||
import { UniqueID } from "@repo/rdx-ddd";
|
||||
@ -17,8 +16,7 @@ export class ListCustomerInvoicesUseCase {
|
||||
constructor(
|
||||
private readonly service: CustomerInvoiceService,
|
||||
private readonly transactionManager: ITransactionManager,
|
||||
private readonly assembler: ListCustomerInvoicesAssembler,
|
||||
private readonly taxCatalog: JsonTaxCatalogProvider
|
||||
private readonly assembler: ListCustomerInvoicesAssembler
|
||||
) {}
|
||||
|
||||
public execute(
|
||||
|
||||
@ -30,22 +30,10 @@ export interface CustomerInvoiceProps {
|
||||
operationDate: Maybe<UtcDate>;
|
||||
|
||||
customerId: UniqueID;
|
||||
|
||||
recipient: Maybe<InvoiceRecipient>;
|
||||
|
||||
notes: Maybe<TextValue>;
|
||||
|
||||
//dueDate: UtcDate; // ? --> depende de la forma de pago
|
||||
|
||||
//tax: Tax; // ? --> detalles?
|
||||
|
||||
//purchareOrderNumber: string;
|
||||
|
||||
//senderId: UniqueID;
|
||||
|
||||
//paymentInstructions: Note;
|
||||
//paymentTerms: string;
|
||||
|
||||
languageCode: LanguageCode;
|
||||
currencyCode: CurrencyCode;
|
||||
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
import {
|
||||
City,
|
||||
Country,
|
||||
Name,
|
||||
PostalCode,
|
||||
Province,
|
||||
Street,
|
||||
TINNumber,
|
||||
ValueObject
|
||||
City,
|
||||
Country,
|
||||
Name,
|
||||
PostalCode,
|
||||
Province,
|
||||
Street,
|
||||
TINNumber,
|
||||
ValueObject,
|
||||
} from "@repo/rdx-ddd";
|
||||
import { Maybe, Result } from "@repo/rdx-utils";
|
||||
import * as z from "zod/v4";
|
||||
|
||||
export interface InvoiceRecipientProps {
|
||||
name: Name;
|
||||
@ -23,26 +22,15 @@ export interface InvoiceRecipientProps {
|
||||
}
|
||||
|
||||
export class InvoiceRecipient extends ValueObject<InvoiceRecipientProps> {
|
||||
protected static validate(values: InvoiceRecipientProps) {
|
||||
const schema = z.object({
|
||||
name: z.string(),
|
||||
tin: z.string(),
|
||||
street: z.string().optional(),
|
||||
street2: z.string().optional(),
|
||||
city: z.string().optional(),
|
||||
postalCode: z.string().optional(),
|
||||
province: z.string().optional(),
|
||||
country: z.string().optional(),
|
||||
})
|
||||
|
||||
return schema.safeParse(values);
|
||||
}
|
||||
protected static validate(values: InvoiceRecipientProps) {
|
||||
return Result.ok(values);
|
||||
}
|
||||
|
||||
static create(values: InvoiceRecipientProps): Result<InvoiceRecipient, Error> {
|
||||
const valueIsValid = InvoiceRecipient.validate(values)
|
||||
const valueIsValid = InvoiceRecipient.validate(values);
|
||||
|
||||
if (!valueIsValid.success) {
|
||||
return Result.fail(new Error(valueIsValid.error.issues[0].message));
|
||||
if (valueIsValid.isFailure) {
|
||||
return Result.fail(valueIsValid.error);
|
||||
}
|
||||
|
||||
return Result.ok(new InvoiceRecipient(values));
|
||||
@ -57,7 +45,6 @@ export class InvoiceRecipient extends ValueObject<InvoiceRecipientProps> {
|
||||
return InvoiceRecipient.create(updatedProps);
|
||||
}
|
||||
|
||||
|
||||
public get name(): Name {
|
||||
return this.props.name;
|
||||
}
|
||||
@ -97,7 +84,4 @@ export class InvoiceRecipient extends ValueObject<InvoiceRecipientProps> {
|
||||
toPrimitive() {
|
||||
return this.getProps();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -58,7 +58,7 @@ export const customerInvoicesRouter = (params: ModuleParams) => {
|
||||
);
|
||||
|
||||
router.get(
|
||||
"/:id",
|
||||
"/:invoice_id",
|
||||
//checkTabContext,
|
||||
validateRequest(GetCustomerInvoiceByIdRequestSchema, "params"),
|
||||
(req: Request, res: Response, next: NextFunction) => {
|
||||
@ -81,7 +81,7 @@ export const customerInvoicesRouter = (params: ModuleParams) => {
|
||||
);
|
||||
|
||||
/*router.put(
|
||||
"/:customer_id",
|
||||
"/:invoice_id",
|
||||
//checkTabContext,
|
||||
validateRequest(UpdateCustomerInvoiceByIdParamsRequestSchema, "params"),
|
||||
validateRequest(UpdateCustomerInvoiceByIdRequestSchema, "body"),
|
||||
@ -93,7 +93,7 @@ export const customerInvoicesRouter = (params: ModuleParams) => {
|
||||
);*/
|
||||
|
||||
router.delete(
|
||||
"/:id",
|
||||
"/:invoice_id",
|
||||
//checkTabContext,
|
||||
|
||||
validateRequest(DeleteCustomerInvoiceByIdRequestSchema, "params"),
|
||||
|
||||
@ -121,10 +121,12 @@ export class CustomerInvoiceMapper
|
||||
);
|
||||
|
||||
const discountPercentage = extractOrPushError(
|
||||
Percentage.create({
|
||||
value: source.discount_percentage_value,
|
||||
scale: source.discount_percentage_scale,
|
||||
}),
|
||||
maybeFromNullableVO(source.discount_percentage_value, (value) =>
|
||||
Percentage.create({
|
||||
value: value,
|
||||
scale: source.discount_percentage_scale,
|
||||
})
|
||||
),
|
||||
"discount_percentage",
|
||||
errors
|
||||
);
|
||||
|
||||
@ -114,8 +114,17 @@ export class CustomerInvoiceRepository
|
||||
transaction: Transaction
|
||||
): Promise<Result<CustomerInvoice, Error>> {
|
||||
try {
|
||||
const { CustomerModel } = this._database.models;
|
||||
|
||||
const row = await CustomerInvoiceModel.findOne({
|
||||
where: { id: id.toString(), company_id: companyId.toString() },
|
||||
include: [
|
||||
{
|
||||
model: CustomerModel,
|
||||
as: "current_customer",
|
||||
required: false, // false => LEFT JOIN
|
||||
},
|
||||
],
|
||||
transaction,
|
||||
});
|
||||
|
||||
@ -169,8 +178,6 @@ export class CustomerInvoiceRepository
|
||||
transaction,
|
||||
});
|
||||
|
||||
console.log(instances);
|
||||
|
||||
return this._mapper.mapArrayToDomain(instances);
|
||||
} catch (err: unknown) {
|
||||
return Result.fail(translateSequelizeError(err));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user