.
This commit is contained in:
parent
4ab4b886f4
commit
603b5fed8e
@ -1,5 +1,6 @@
|
|||||||
export * from "./list.dto";
|
|
||||||
export * from "./error.dto";
|
export * from "./error.dto";
|
||||||
|
export * from "./list.dto";
|
||||||
|
export * from "./metadata.dto";
|
||||||
export * from "./money.dto";
|
export * from "./money.dto";
|
||||||
export * from "./percentage.dto";
|
export * from "./percentage.dto";
|
||||||
export * from "./quantity.dto";
|
export * from "./quantity.dto";
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
export interface IListResponseDTO<T> {
|
export interface IListResponseDTO<T> {
|
||||||
page: number;
|
page: number;
|
||||||
perpage: number;
|
per_page: number;
|
||||||
total_pages: number;
|
total_pages: number;
|
||||||
total_items: number;
|
total_items: number;
|
||||||
items: T[];
|
items: T[];
|
||||||
|
|||||||
16
modules/core/src/dto/metadata.dto.ts
Normal file
16
modules/core/src/dto/metadata.dto.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
export interface IMetadataDTO {
|
||||||
|
entity: string;
|
||||||
|
version: string;
|
||||||
|
[key: string]: any; // <- para campos adicionales futuros
|
||||||
|
|
||||||
|
// Futuros campos opcionales que podrían ser útiles:
|
||||||
|
// source?: 'api' | 'manual' | 'imported' | string;
|
||||||
|
// related_id?: string;
|
||||||
|
// related_entity?: string;
|
||||||
|
// created_by?: string;
|
||||||
|
// created_at?: string;
|
||||||
|
// updated_by?: string;
|
||||||
|
// updated_at?: string;
|
||||||
|
// permissions?: Array<'read' | 'edit' | 'delete' | string>;
|
||||||
|
// visibility?: 'public' | 'private' | 'restricted' | string;
|
||||||
|
}
|
||||||
@ -4,7 +4,7 @@ import Joi from "joi";
|
|||||||
export interface IMoneyDTO {
|
export interface IMoneyDTO {
|
||||||
amount: number | null;
|
amount: number | null;
|
||||||
scale: number;
|
scale: number;
|
||||||
currencycode: string;
|
currency_code: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IMoneyRequestDTO extends IMoneyDTO {}
|
export interface IMoneyRequestDTO extends IMoneyDTO {}
|
||||||
|
|||||||
@ -18,14 +18,7 @@ export class ListInvoicesController extends ExpressController {
|
|||||||
return this.handleError(invoicesOrError.error);
|
return this.handleError(invoicesOrError.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.ok(
|
return this.ok(this.presenter.toDTO(invoicesOrError.data, criteria));
|
||||||
this.presenter.toDTO(
|
|
||||||
invoicesOrError.data /*, {
|
|
||||||
page: criteria.pagination.offset,
|
|
||||||
limit: criteria.pagination.limit,
|
|
||||||
}*/
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleError(error: Error) {
|
private handleError(error: Error) {
|
||||||
|
|||||||
@ -1,15 +1,23 @@
|
|||||||
|
import { IListResponseDTO } from "@erp/core";
|
||||||
|
import { Criteria } from "@repo/rdx-criteria";
|
||||||
import { Collection } from "@repo/rdx-utils";
|
import { Collection } from "@repo/rdx-utils";
|
||||||
import { IListInvoicesResponseDTO } from "../../../../common/dto";
|
import { IListInvoicesResponseDTO } from "../../../../common/dto";
|
||||||
import { Invoice } from "../../../domain";
|
import { Invoice } from "../../../domain";
|
||||||
|
|
||||||
export interface IListInvoicesPresenter {
|
export interface IListInvoicesPresenter {
|
||||||
toDTO: (invoices: Collection<Invoice>) => IListInvoicesResponseDTO[];
|
toDTO: (
|
||||||
|
invoices: Collection<Invoice>,
|
||||||
|
criteria: Criteria
|
||||||
|
) => IListResponseDTO<IListInvoicesResponseDTO>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const listInvoicesPresenter: IListInvoicesPresenter = {
|
export const listInvoicesPresenter: IListInvoicesPresenter = {
|
||||||
toDTO: (invoices: Collection<Invoice>): IListInvoicesResponseDTO[] => {
|
toDTO: (
|
||||||
|
invoices: Collection<Invoice>,
|
||||||
|
criteria: Criteria
|
||||||
|
): IListResponseDTO<IListInvoicesResponseDTO> => {
|
||||||
const items = invoices.map((invoice) => {
|
const items = invoices.map((invoice) => {
|
||||||
const result = {
|
return {
|
||||||
id: invoice.id.toPrimitive(),
|
id: invoice.id.toPrimitive(),
|
||||||
|
|
||||||
invoice_status: invoice.status.toString(),
|
invoice_status: invoice.status.toString(),
|
||||||
@ -18,24 +26,27 @@ export const listInvoicesPresenter: IListInvoicesPresenter = {
|
|||||||
issue_date: invoice.issueDate.toISOString(),
|
issue_date: invoice.issueDate.toISOString(),
|
||||||
operation_date: invoice.operationDate.toISOString(),
|
operation_date: invoice.operationDate.toISOString(),
|
||||||
language_code: "ES",
|
language_code: "ES",
|
||||||
|
|
||||||
currency: invoice.invoiceCurrency.toString(),
|
currency: invoice.invoiceCurrency.toString(),
|
||||||
subtotal: invoice.calculateSubtotal().toPrimitive(),
|
subtotal: invoice.calculateSubtotal().toPrimitive(),
|
||||||
total: invoice.calculateTotal().toPrimitive(),
|
total: invoice.calculateTotal().toPrimitive(),
|
||||||
|
|
||||||
//recipient: InvoiceParticipantPresenter(invoice.recipient),
|
//recipient: InvoiceParticipantPresenter(invoice.recipient),
|
||||||
};
|
|
||||||
|
|
||||||
return result;
|
metadata: {
|
||||||
|
entity: "invoice",
|
||||||
|
},
|
||||||
|
} as IListInvoicesResponseDTO;
|
||||||
});
|
});
|
||||||
|
|
||||||
invoices.size();
|
const totalItems = invoices.total();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
//page,
|
page: criteria.pageNumber,
|
||||||
//per_page: limit,
|
per_page: criteria.pageSize,
|
||||||
//total_pages: Math.ceil(invoices.total() / limit),
|
total_pages: Math.ceil(totalItems / criteria.pageSize),
|
||||||
//total_items: totalCount,
|
total_items: totalItems,
|
||||||
items,
|
items: items,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { IMoneyDTO, IQuantityDTO } from "@erp/core";
|
import { IMetadataDTO, IMoneyDTO, IQuantityDTO } from "@erp/core";
|
||||||
|
|
||||||
export interface IListInvoicesResponseDTO {
|
export interface IListInvoicesResponseDTO {
|
||||||
id: string;
|
id: string;
|
||||||
@ -13,6 +13,8 @@ export interface IListInvoicesResponseDTO {
|
|||||||
|
|
||||||
subtotal: IMoneyDTO;
|
subtotal: IMoneyDTO;
|
||||||
total: IMoneyDTO;
|
total: IMoneyDTO;
|
||||||
|
|
||||||
|
metadata?: IMetadataDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IGetInvoiceResponseDTO {
|
export interface IGetInvoiceResponseDTO {
|
||||||
@ -40,6 +42,8 @@ export interface IGetInvoiceResponseDTO {
|
|||||||
}[];
|
}[];
|
||||||
|
|
||||||
//customer:
|
//customer:
|
||||||
|
|
||||||
|
metadata?: IMetadataDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICreateInvoiceResponseDTO {
|
export interface ICreateInvoiceResponseDTO {
|
||||||
|
|||||||
39
packages/rdx-criteria/src/critera.ts
Normal file
39
packages/rdx-criteria/src/critera.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { Criteria as BaseCriteria, Filters, FiltersPrimitives, Order } from "@codelytv/criteria";
|
||||||
|
import { INITIAL_PAGE_INDEX, INITIAL_PAGE_SIZE } from './defaults';
|
||||||
|
|
||||||
|
export class Criteria extends BaseCriteria {
|
||||||
|
/**
|
||||||
|
* Creates a new Criteria instance.
|
||||||
|
*
|
||||||
|
* @param filters - The filters to apply.
|
||||||
|
* @param order - The order to apply.
|
||||||
|
* @param pageSize - The size of the page.
|
||||||
|
* @param pageNumber - The number of the page.
|
||||||
|
*/
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
public readonly filters: Filters,
|
||||||
|
public readonly order: Order,
|
||||||
|
public readonly pageSize: number,
|
||||||
|
public readonly pageNumber: number
|
||||||
|
) {
|
||||||
|
super(filters, order, pageSize, pageNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromPrimitives(
|
||||||
|
filters: FiltersPrimitives[],
|
||||||
|
orderBy: string | null,
|
||||||
|
orderType: string | null,
|
||||||
|
pageSize: number | null,
|
||||||
|
pageNumber: number | null,
|
||||||
|
): Criteria {
|
||||||
|
|
||||||
|
|
||||||
|
return new Criteria(
|
||||||
|
Filters.fromPrimitives(filters),
|
||||||
|
Order.fromPrimitives(orderBy, orderType),
|
||||||
|
pageSize ?? INITIAL_PAGE_SIZE,
|
||||||
|
pageNumber ?? INITIAL_PAGE_INDEX,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import { Criteria, FiltersPrimitives } from "@codelytv/criteria";
|
import { FiltersPrimitives } from "@codelytv/criteria";
|
||||||
|
import { Criteria } from "./critera";
|
||||||
import { DEFAULT_ORDER, INITIAL_PAGE_INDEX, INITIAL_PAGE_SIZE } from "./defaults";
|
import { DEFAULT_ORDER, INITIAL_PAGE_INDEX, INITIAL_PAGE_SIZE } from "./defaults";
|
||||||
|
|
||||||
type defaultsType = {
|
type defaultsType = {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { Criteria, Filter } from "@codelytv/criteria";
|
import { Filter } from "@codelytv/criteria";
|
||||||
import { FindOptions, Op, OrderItem, WhereOptions } from "sequelize";
|
import { FindOptions, Op, OrderItem, WhereOptions } from "sequelize";
|
||||||
|
import { Criteria } from "./critera";
|
||||||
|
|
||||||
type Mappings = { [key: string]: string };
|
type Mappings = { [key: string]: string };
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
export * from "@codelytv/criteria";
|
export * from "./critera";
|
||||||
export * from "./criteria-from-url-converter";
|
export * from "./criteria-from-url-converter";
|
||||||
export * from "./criteria-to-sequelize-converter";
|
export * from "./criteria-to-sequelize-converter";
|
||||||
export * from "./defaults";
|
export * from "./defaults";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user