.
This commit is contained in:
parent
4ab4b886f4
commit
603b5fed8e
@ -1,5 +1,6 @@
|
||||
export * from "./list.dto";
|
||||
export * from "./error.dto";
|
||||
export * from "./list.dto";
|
||||
export * from "./metadata.dto";
|
||||
export * from "./money.dto";
|
||||
export * from "./percentage.dto";
|
||||
export * from "./quantity.dto";
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
export interface IListResponseDTO<T> {
|
||||
page: number;
|
||||
perpage: number;
|
||||
per_page: number;
|
||||
total_pages: number;
|
||||
total_items: number;
|
||||
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 {
|
||||
amount: number | null;
|
||||
scale: number;
|
||||
currencycode: string;
|
||||
currency_code: string;
|
||||
}
|
||||
|
||||
export interface IMoneyRequestDTO extends IMoneyDTO {}
|
||||
|
||||
@ -18,14 +18,7 @@ export class ListInvoicesController extends ExpressController {
|
||||
return this.handleError(invoicesOrError.error);
|
||||
}
|
||||
|
||||
return this.ok(
|
||||
this.presenter.toDTO(
|
||||
invoicesOrError.data /*, {
|
||||
page: criteria.pagination.offset,
|
||||
limit: criteria.pagination.limit,
|
||||
}*/
|
||||
)
|
||||
);
|
||||
return this.ok(this.presenter.toDTO(invoicesOrError.data, criteria));
|
||||
}
|
||||
|
||||
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 { IListInvoicesResponseDTO } from "../../../../common/dto";
|
||||
import { Invoice } from "../../../domain";
|
||||
|
||||
export interface IListInvoicesPresenter {
|
||||
toDTO: (invoices: Collection<Invoice>) => IListInvoicesResponseDTO[];
|
||||
toDTO: (
|
||||
invoices: Collection<Invoice>,
|
||||
criteria: Criteria
|
||||
) => IListResponseDTO<IListInvoicesResponseDTO>;
|
||||
}
|
||||
|
||||
export const listInvoicesPresenter: IListInvoicesPresenter = {
|
||||
toDTO: (invoices: Collection<Invoice>): IListInvoicesResponseDTO[] => {
|
||||
toDTO: (
|
||||
invoices: Collection<Invoice>,
|
||||
criteria: Criteria
|
||||
): IListResponseDTO<IListInvoicesResponseDTO> => {
|
||||
const items = invoices.map((invoice) => {
|
||||
const result = {
|
||||
return {
|
||||
id: invoice.id.toPrimitive(),
|
||||
|
||||
invoice_status: invoice.status.toString(),
|
||||
@ -18,24 +26,27 @@ export const listInvoicesPresenter: IListInvoicesPresenter = {
|
||||
issue_date: invoice.issueDate.toISOString(),
|
||||
operation_date: invoice.operationDate.toISOString(),
|
||||
language_code: "ES",
|
||||
|
||||
currency: invoice.invoiceCurrency.toString(),
|
||||
subtotal: invoice.calculateSubtotal().toPrimitive(),
|
||||
total: invoice.calculateTotal().toPrimitive(),
|
||||
|
||||
//recipient: InvoiceParticipantPresenter(invoice.recipient),
|
||||
};
|
||||
|
||||
return result;
|
||||
metadata: {
|
||||
entity: "invoice",
|
||||
},
|
||||
} as IListInvoicesResponseDTO;
|
||||
});
|
||||
|
||||
invoices.size();
|
||||
const totalItems = invoices.total();
|
||||
|
||||
return {
|
||||
//page,
|
||||
//per_page: limit,
|
||||
//total_pages: Math.ceil(invoices.total() / limit),
|
||||
//total_items: totalCount,
|
||||
items,
|
||||
page: criteria.pageNumber,
|
||||
per_page: criteria.pageSize,
|
||||
total_pages: Math.ceil(totalItems / criteria.pageSize),
|
||||
total_items: totalItems,
|
||||
items: items,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { IMoneyDTO, IQuantityDTO } from "@erp/core";
|
||||
import { IMetadataDTO, IMoneyDTO, IQuantityDTO } from "@erp/core";
|
||||
|
||||
export interface IListInvoicesResponseDTO {
|
||||
id: string;
|
||||
@ -13,6 +13,8 @@ export interface IListInvoicesResponseDTO {
|
||||
|
||||
subtotal: IMoneyDTO;
|
||||
total: IMoneyDTO;
|
||||
|
||||
metadata?: IMetadataDTO;
|
||||
}
|
||||
|
||||
export interface IGetInvoiceResponseDTO {
|
||||
@ -40,6 +42,8 @@ export interface IGetInvoiceResponseDTO {
|
||||
}[];
|
||||
|
||||
//customer:
|
||||
|
||||
metadata?: IMetadataDTO;
|
||||
}
|
||||
|
||||
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";
|
||||
|
||||
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 { Criteria } from "./critera";
|
||||
|
||||
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-to-sequelize-converter";
|
||||
export * from "./defaults";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user