.
This commit is contained in:
parent
ab36d6e084
commit
b9efe95289
@ -20,10 +20,10 @@ class ArticleMapper
|
|||||||
const id_article = this.mapsValue(source, "id_article", ArticleIdentifier.create);
|
const id_article = this.mapsValue(source, "id_article", ArticleIdentifier.create);
|
||||||
const reference = this.mapsValue(source, "reference", Slug.create);
|
const reference = this.mapsValue(source, "reference", Slug.create);
|
||||||
const points = this.mapsValue(source, "points", (value: any) =>
|
const points = this.mapsValue(source, "points", (value: any) =>
|
||||||
Quantity.create({ amount: value, precision: 4 })
|
Quantity.create({ amount: value, scale: 4 })
|
||||||
);
|
);
|
||||||
const retail_price = this.mapsValue(source, "retail_price", (value: any) =>
|
const retail_price = this.mapsValue(source, "retail_price", (value: any) =>
|
||||||
UnitPrice.create({ amount: value, precision: 4 })
|
UnitPrice.create({ amount: value, scale: 4 })
|
||||||
);
|
);
|
||||||
|
|
||||||
const language = this.mapsValue(source, "lang_code", Language.createFromCode);
|
const language = this.mapsValue(source, "lang_code", Language.createFromCode);
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
// https://github.com/Hodor9898/sequelize-query-builder/blob/master/index.ts
|
|
||||||
|
|
||||||
import { IOrder, IOrderCollection } from "@shared/contexts";
|
import { IOrder, IOrderCollection } from "@shared/contexts";
|
||||||
|
|
||||||
export class SequelizeParseOrder {
|
export class SequelizeParseOrder {
|
||||||
// eslint-disable-next-line unused-imports/no-unused-vars, @typescript-eslint/no-unused-vars
|
|
||||||
static parseOrder(orderCollection: IOrderCollection): any {
|
static parseOrder(orderCollection: IOrderCollection): any {
|
||||||
if (orderCollection.totalCount === 0) {
|
if (orderCollection.totalCount === 0) {
|
||||||
return null;
|
return null;
|
||||||
@ -24,3 +21,7 @@ export class SequelizeParseOrder {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// https://github.com/Hodor9898/sequelize-query-builder/blob/master/index.ts
|
||||||
|
*/
|
||||||
|
|||||||
@ -10,11 +10,11 @@ export const UpdateProfilePresenter: IUpdateProfilePresenter = {
|
|||||||
map: (profile: Profile, context: IProfileContext): IUpdateProfileResponse_DTO => {
|
map: (profile: Profile, context: IProfileContext): IUpdateProfileResponse_DTO => {
|
||||||
return {
|
return {
|
||||||
dealer_id: profile.id.toString(),
|
dealer_id: profile.id.toString(),
|
||||||
contact_information: profile.contactInformation,
|
contact_information: profile.contactInformation.toString(),
|
||||||
default_payment_method: profile.defaultPaymentMethod,
|
default_payment_method: profile.defaultPaymentMethod.toString(),
|
||||||
default_notes: profile.defaultNotes,
|
default_notes: profile.defaultNotes.toString(),
|
||||||
default_legal_terms: profile.defaultLegalTerms,
|
default_legal_terms: profile.defaultLegalTerms.toString(),
|
||||||
default_quote_validity: profile.defaultQuoteValidity,
|
default_quote_validity: profile.defaultQuoteValidity.toString(),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -3,16 +3,18 @@ import { IRepositoryManager } from "@/contexts/common/domain";
|
|||||||
import { IInfrastructureError } from "@/contexts/common/infrastructure";
|
import { IInfrastructureError } from "@/contexts/common/infrastructure";
|
||||||
import { ISequelizeAdapter } from "@/contexts/common/infrastructure/sequelize";
|
import { ISequelizeAdapter } from "@/contexts/common/infrastructure/sequelize";
|
||||||
import {
|
import {
|
||||||
|
CurrencyData,
|
||||||
DomainError,
|
DomainError,
|
||||||
ICreateDealer_Request_DTO,
|
ICreateDealer_Request_DTO,
|
||||||
IDomainError,
|
IDomainError,
|
||||||
|
Language,
|
||||||
Name,
|
Name,
|
||||||
Result,
|
Result,
|
||||||
UniqueID,
|
UniqueID,
|
||||||
ensureIdIsValid,
|
ensureIdIsValid,
|
||||||
ensureNameIsValid,
|
ensureNameIsValid,
|
||||||
} from "@shared/contexts";
|
} from "@shared/contexts";
|
||||||
import { Dealer, IDealerRepository } from "../../domain";
|
import { Dealer, DealerStatus, IDealerRepository } from "../../domain";
|
||||||
|
|
||||||
export type CreateDealerResponseOrError =
|
export type CreateDealerResponseOrError =
|
||||||
| Result<never, IUseCaseError> // Misc errors (value objects)
|
| Result<never, IUseCaseError> // Misc errors (value objects)
|
||||||
@ -119,6 +121,10 @@ export class CreateDealerUseCase
|
|||||||
return Dealer.create(
|
return Dealer.create(
|
||||||
{
|
{
|
||||||
name: nameOrError.object,
|
name: nameOrError.object,
|
||||||
|
currency: CurrencyData.createDefaultCode().object,
|
||||||
|
language: Language.createDefaultCode().object,
|
||||||
|
status: DealerStatus.createActive(),
|
||||||
|
//user_id: user
|
||||||
},
|
},
|
||||||
dealerId
|
dealerId
|
||||||
);
|
);
|
||||||
|
|||||||
@ -194,11 +194,11 @@ export class CreateQuoteUseCase
|
|||||||
unitPrice: UnitPrice.create({
|
unitPrice: UnitPrice.create({
|
||||||
amount: item.unit_price?.amount,
|
amount: item.unit_price?.amount,
|
||||||
currencyCode: item.unit_price?.currency_code,
|
currencyCode: item.unit_price?.currency_code,
|
||||||
precision: item.unit_price?.precision,
|
scale: item.unit_price?.scale,
|
||||||
}).object,
|
}).object,
|
||||||
discount: Percentage.create({
|
discount: Percentage.create({
|
||||||
amount: item.discount?.amount,
|
amount: item.discount?.amount,
|
||||||
precision: item.discount?.precision,
|
scale: item.discount?.scale,
|
||||||
}).object,
|
}).object,
|
||||||
}).object
|
}).object
|
||||||
)
|
)
|
||||||
|
|||||||
@ -193,11 +193,11 @@ export class UpdateQuoteUseCase
|
|||||||
unitPrice: UnitPrice.create({
|
unitPrice: UnitPrice.create({
|
||||||
amount: item.unit_price?.amount,
|
amount: item.unit_price?.amount,
|
||||||
currencyCode: item.unit_price?.currency_code,
|
currencyCode: item.unit_price?.currency_code,
|
||||||
precision: item.unit_price?.precision,
|
scale: item.unit_price?.scale,
|
||||||
}).object,
|
}).object,
|
||||||
discount: Percentage.create({
|
discount: Percentage.create({
|
||||||
amount: item.discount?.amount,
|
amount: item.discount?.amount,
|
||||||
precision: item.discount?.precision,
|
scale: item.discount?.scale,
|
||||||
}).object,
|
}).object,
|
||||||
}).object
|
}).object
|
||||||
)
|
)
|
||||||
|
|||||||
@ -76,7 +76,7 @@ export class Quote extends AggregateRoot<IQuoteProps> implements IQuote {
|
|||||||
.toArray()
|
.toArray()
|
||||||
.reduce<MoneyValue>(
|
.reduce<MoneyValue>(
|
||||||
(accumulator, currentItem) => accumulator.add(currentItem.subtotalPrice),
|
(accumulator, currentItem) => accumulator.add(currentItem.subtotalPrice),
|
||||||
MoneyValue.create({ amount: 0, precision: 2, currencyCode: this.currency.code }).object
|
MoneyValue.create({ amount: 0, scale: 2, currencyCode: this.currency.code }).object
|
||||||
);
|
);
|
||||||
|
|
||||||
protected constructor(props: IQuoteProps, id?: UniqueID) {
|
protected constructor(props: IQuoteProps, id?: UniqueID) {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import {
|
|||||||
} from "@shared/contexts";
|
} from "@shared/contexts";
|
||||||
|
|
||||||
export interface IQuoteItemProps extends IEntityProps {
|
export interface IQuoteItemProps extends IEntityProps {
|
||||||
articleId: string;
|
articleId: string | null;
|
||||||
description: Description; // Descripción del artículo o servicio
|
description: Description; // Descripción del artículo o servicio
|
||||||
quantity: Quantity; // Cantidad de unidades
|
quantity: Quantity; // Cantidad de unidades
|
||||||
unitPrice: MoneyValue; // Precio unitario en la moneda de la factura
|
unitPrice: MoneyValue; // Precio unitario en la moneda de la factura
|
||||||
@ -21,7 +21,7 @@ export interface IQuoteItemProps extends IEntityProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IQuoteItem {
|
export interface IQuoteItem {
|
||||||
articleId: string;
|
articleId: string | null;
|
||||||
description: Description;
|
description: Description;
|
||||||
quantity: Quantity;
|
quantity: Quantity;
|
||||||
unitPrice: MoneyValue;
|
unitPrice: MoneyValue;
|
||||||
@ -35,7 +35,7 @@ export class QuoteItem extends Entity<IQuoteItemProps> implements IQuoteItem {
|
|||||||
return Result.ok(new QuoteItem(props, id));
|
return Result.ok(new QuoteItem(props, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
get articleId(): string {
|
get articleId(): string | null {
|
||||||
return this.props.articleId;
|
return this.props.articleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@ export const GetDealerPresenter: IGetDealerPresenter = {
|
|||||||
return {
|
return {
|
||||||
id: dealer.id.toString(),
|
id: dealer.id.toString(),
|
||||||
name: dealer.name.toString(),
|
name: dealer.name.toString(),
|
||||||
|
lang_code: dealer.language.code,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -21,6 +21,8 @@ export const listDealersPresenter: IListDealersPresenter = {
|
|||||||
return {
|
return {
|
||||||
id: dealer.id.toString(),
|
id: dealer.id.toString(),
|
||||||
name: dealer.name.toString(),
|
name: dealer.name.toString(),
|
||||||
|
lang_code: dealer.language.code,
|
||||||
|
status: dealer.status.toString(),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -41,17 +41,17 @@ const quoteItemPresenter = (items: ICollection<QuoteItem>, context: ISalesContex
|
|||||||
unit_measure: "",
|
unit_measure: "",
|
||||||
unit_price: {
|
unit_price: {
|
||||||
amount: 0,
|
amount: 0,
|
||||||
precision: 2,
|
scale: 2,
|
||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
},
|
},
|
||||||
subtotal: {
|
subtotal: {
|
||||||
amount: 0,
|
amount: 0,
|
||||||
precision: 2,
|
scale: 2,
|
||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
},
|
},
|
||||||
total: {
|
total: {
|
||||||
amount: 0,
|
amount: 0,
|
||||||
precision: 2,
|
scale: 2,
|
||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|||||||
@ -43,7 +43,7 @@ const quoteItemPresenter = (
|
|||||||
): IGetQuote_QuoteItem_Response_DTO[] =>
|
): IGetQuote_QuoteItem_Response_DTO[] =>
|
||||||
items.totalCount > 0
|
items.totalCount > 0
|
||||||
? items.items.map((item: QuoteItem) => ({
|
? items.items.map((item: QuoteItem) => ({
|
||||||
article_id: item.articleId,
|
article_id: item.articleId ?? "",
|
||||||
description: item.description.toString(),
|
description: item.description.toString(),
|
||||||
quantity: item.quantity.toObject(),
|
quantity: item.quantity.toObject(),
|
||||||
unit_price: item.unitPrice.toObject(),
|
unit_price: item.unitPrice.toObject(),
|
||||||
|
|||||||
@ -64,7 +64,7 @@ class QuoteMapper
|
|||||||
discount: this.mapsValue(source, "discount", (discount) =>
|
discount: this.mapsValue(source, "discount", (discount) =>
|
||||||
Percentage.create({
|
Percentage.create({
|
||||||
amount: discount,
|
amount: discount,
|
||||||
precision: Percentage.DEFAULT_PRECISION,
|
scale: Percentage.DEFAULT_SCALE,
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|||||||
@ -28,14 +28,14 @@ class QuoteItemMapper
|
|||||||
quantity: this.mapsValue(source, "quantity", (quantity) =>
|
quantity: this.mapsValue(source, "quantity", (quantity) =>
|
||||||
Quantity.create({
|
Quantity.create({
|
||||||
amount: quantity,
|
amount: quantity,
|
||||||
precision: Quantity.DEFAULT_PRECISION,
|
scale: Quantity.DEFAULT_SCALE,
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
unitPrice: this.mapsValue(source, "unit_price", (unit_price) =>
|
unitPrice: this.mapsValue(source, "unit_price", (unit_price) =>
|
||||||
MoneyValue.create({
|
MoneyValue.create({
|
||||||
amount: unit_price,
|
amount: unit_price,
|
||||||
currencyCode: sourceParent.currency_code,
|
currencyCode: sourceParent.currency_code,
|
||||||
precision: 4,
|
scale: 4,
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ class QuoteItemMapper
|
|||||||
MoneyValue.create({
|
MoneyValue.create({
|
||||||
amount: subtotal_price,
|
amount: subtotal_price,
|
||||||
currencyCode: sourceParent.currency_code,
|
currencyCode: sourceParent.currency_code,
|
||||||
precision: 4,
|
scale: 4,
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
*/
|
*/
|
||||||
@ -51,7 +51,7 @@ class QuoteItemMapper
|
|||||||
discount: this.mapsValue(source, "discount", (discount) =>
|
discount: this.mapsValue(source, "discount", (discount) =>
|
||||||
Percentage.create({
|
Percentage.create({
|
||||||
amount: discount,
|
amount: discount,
|
||||||
precision: Percentage.DEFAULT_PRECISION,
|
scale: Percentage.DEFAULT_SCALE,
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ class QuoteItemMapper
|
|||||||
MoneyValue.create({
|
MoneyValue.create({
|
||||||
amount: total_price,
|
amount: total_price,
|
||||||
currencyCode: sourceParent.currency_code,
|
currencyCode: sourceParent.currency_code,
|
||||||
precision: 2,
|
scale: 2,
|
||||||
})
|
})
|
||||||
),*/
|
),*/
|
||||||
};
|
};
|
||||||
|
|||||||
@ -46,7 +46,7 @@ export class Dealer_Model extends Model<
|
|||||||
}
|
}
|
||||||
|
|
||||||
declare id: string;
|
declare id: string;
|
||||||
declare contact_id?: CreationOptional<string>;
|
declare contact_id?: CreationOptional<string | null>;
|
||||||
declare name: CreationOptional<string>;
|
declare name: CreationOptional<string>;
|
||||||
declare contact_information: CreationOptional<string>;
|
declare contact_information: CreationOptional<string>;
|
||||||
declare default_payment_method: CreationOptional<string>;
|
declare default_payment_method: CreationOptional<string>;
|
||||||
|
|||||||
@ -30,14 +30,14 @@ export class QuoteItem_Model extends Model<
|
|||||||
|
|
||||||
declare quote_id: string;
|
declare quote_id: string;
|
||||||
declare item_id: string;
|
declare item_id: string;
|
||||||
declare id_article: string; // number ??
|
declare id_article: CreationOptional<string | null>;
|
||||||
declare position: number;
|
declare position: number;
|
||||||
declare description: CreationOptional<string>;
|
declare description: CreationOptional<string | null>;
|
||||||
declare quantity: CreationOptional<number>;
|
declare quantity: CreationOptional<number | null>;
|
||||||
declare unit_price: CreationOptional<number>;
|
declare unit_price: CreationOptional<number | null>;
|
||||||
declare subtotal_price: CreationOptional<number>;
|
declare subtotal_price: CreationOptional<number | null>;
|
||||||
declare discount: CreationOptional<number>;
|
declare discount: CreationOptional<number | null>;
|
||||||
declare total_price: CreationOptional<number>;
|
declare total_price: CreationOptional<number | null>;
|
||||||
|
|
||||||
declare quote: NonAttribute<Quote_Model>;
|
declare quote: NonAttribute<Quote_Model>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import {
|
|||||||
Email,
|
Email,
|
||||||
ICreateUser_Request_DTO,
|
ICreateUser_Request_DTO,
|
||||||
IDomainError,
|
IDomainError,
|
||||||
|
Language,
|
||||||
Name,
|
Name,
|
||||||
Result,
|
Result,
|
||||||
UniqueID,
|
UniqueID,
|
||||||
@ -168,6 +169,7 @@ export class CreateUserUseCase
|
|||||||
email: emailOrError.object,
|
email: emailOrError.object,
|
||||||
password: passwordOrError.object,
|
password: passwordOrError.object,
|
||||||
roles: [UserRole.ROLE_USER],
|
roles: [UserRole.ROLE_USER],
|
||||||
|
language: Language.createDefaultCode().object,
|
||||||
},
|
},
|
||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import {
|
|||||||
Email,
|
Email,
|
||||||
IDomainError,
|
IDomainError,
|
||||||
IUpdateUser_Request_DTO,
|
IUpdateUser_Request_DTO,
|
||||||
|
Language,
|
||||||
Name,
|
Name,
|
||||||
Result,
|
Result,
|
||||||
UniqueID,
|
UniqueID,
|
||||||
@ -129,6 +130,7 @@ export class UpdateUserUseCase
|
|||||||
email: emailOrError.object,
|
email: emailOrError.object,
|
||||||
password: passwordOrError.object,
|
password: passwordOrError.object,
|
||||||
roles: [UserRole.ROLE_USER],
|
roles: [UserRole.ROLE_USER],
|
||||||
|
language: Language.createDefaultCode().object,
|
||||||
},
|
},
|
||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
|
|||||||
@ -40,7 +40,7 @@ class UserMapper
|
|||||||
name: source.name.toPrimitive(),
|
name: source.name.toPrimitive(),
|
||||||
email: source.email.toPrimitive(),
|
email: source.email.toPrimitive(),
|
||||||
password: source.password.toPrimitive(),
|
password: source.password.toPrimitive(),
|
||||||
language: source.language.toPrimitive(),
|
lang_code: source.language.toPrimitive(),
|
||||||
roles: source.getRoles().map((rol) => rol.toPrimitive()),
|
roles: source.getRoles().map((rol) => rol.toPrimitive()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { IQuantuty_Response_DTO } from "../../../../common";
|
import { IQuantity_Response_DTO } from "../../../../common";
|
||||||
|
|
||||||
export interface IListArticles_Response_DTO {
|
export interface IListArticles_Response_DTO {
|
||||||
id: string;
|
id: string;
|
||||||
@ -10,5 +10,5 @@ export interface IListArticles_Response_DTO {
|
|||||||
|
|
||||||
description: string;
|
description: string;
|
||||||
points: number;
|
points: number;
|
||||||
retail_price: IQuantuty_Response_DTO;
|
retail_price: IQuantity_Response_DTO;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,11 +69,11 @@ export const ensureDescriptionIsValid = (value: string): Result<boolean, Error>
|
|||||||
};*/
|
};*/
|
||||||
|
|
||||||
export const ensureUnitPriceIsValid = (value: any): Result<boolean, Error> => {
|
export const ensureUnitPriceIsValid = (value: any): Result<boolean, Error> => {
|
||||||
const { amount, currency, precision } = value;
|
const { amount, currency, scale } = value;
|
||||||
const descriptionOrError = UnitPrice.create({
|
const descriptionOrError = UnitPrice.create({
|
||||||
amount,
|
amount,
|
||||||
currencyCode: currency,
|
currencyCode: currency,
|
||||||
precision,
|
scale,
|
||||||
});
|
});
|
||||||
|
|
||||||
return descriptionOrError.isSuccess ? Result.ok(true) : Result.fail(descriptionOrError.error);
|
return descriptionOrError.isSuccess ? Result.ok(true) : Result.fail(descriptionOrError.error);
|
||||||
|
|||||||
@ -1,16 +1,19 @@
|
|||||||
import Joi from "joi";
|
import Joi from "joi";
|
||||||
import { Result, RuleValidator } from "../../domain";
|
import { Result, RuleValidator } from "../../domain";
|
||||||
|
|
||||||
export interface IMoney_Request_DTO {
|
export interface IMoney_DTO {
|
||||||
amount: number;
|
amount: number;
|
||||||
precision: number;
|
scale: number;
|
||||||
currency_code: string;
|
currency_code: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IMoney_Request_DTO extends IMoney_DTO {}
|
||||||
|
export interface IMoney_Response_DTO extends IMoney_DTO {}
|
||||||
|
|
||||||
export function ensureMoney_DTOIsValid(money: IMoney_Request_DTO) {
|
export function ensureMoney_DTOIsValid(money: IMoney_Request_DTO) {
|
||||||
const schema = Joi.object({
|
const schema = Joi.object({
|
||||||
amount: Joi.number(),
|
amount: Joi.number(),
|
||||||
precision: Joi.number(),
|
scale: Joi.number(),
|
||||||
currency_code: Joi.string(),
|
currency_code: Joi.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -22,5 +25,3 @@ export function ensureMoney_DTOIsValid(money: IMoney_Request_DTO) {
|
|||||||
|
|
||||||
return Result.ok(true);
|
return Result.ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IMoney_Response_DTO extends IMoney_Request_DTO {}
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
export interface IPercentage_DTO {
|
export interface IPercentage_DTO {
|
||||||
amount: number;
|
amount: number;
|
||||||
precision: number;
|
scale: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IPercentage_Request_DTO extends IPercentage_DTO {}
|
export interface IPercentage_Request_DTO extends IPercentage_DTO {}
|
||||||
|
|||||||
@ -3,13 +3,13 @@ import { Result, RuleValidator } from "../../domain";
|
|||||||
|
|
||||||
export interface IQuantity_Request_DTO {
|
export interface IQuantity_Request_DTO {
|
||||||
amount: number;
|
amount: number;
|
||||||
precision: number;
|
scale: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ensureQuantity_DTOIsValid(quantity: IQuantity_Request_DTO) {
|
export function ensureQuantity_DTOIsValid(quantity: IQuantity_Request_DTO) {
|
||||||
const schema = Joi.object({
|
const schema = Joi.object({
|
||||||
amount: Joi.number(),
|
amount: Joi.number(),
|
||||||
precision: Joi.number(),
|
scale: Joi.number(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = RuleValidator.validate<IQuantity_Request_DTO>(schema, quantity);
|
const result = RuleValidator.validate<IQuantity_Request_DTO>(schema, quantity);
|
||||||
|
|||||||
@ -14,7 +14,7 @@ describe("MoneyValue Value Object", () => {
|
|||||||
// Prueba la creación de un valor monetario nulo.
|
// Prueba la creación de un valor monetario nulo.
|
||||||
it("Should create a valid null money value", () => {
|
it("Should create a valid null money value", () => {
|
||||||
const nullMoneyValue = MoneyValue.create({
|
const nullMoneyValue = MoneyValue.create({
|
||||||
amount: null
|
amount: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(nullMoneyValue.isSuccess).toBe(true);
|
expect(nullMoneyValue.isSuccess).toBe(true);
|
||||||
@ -43,8 +43,8 @@ describe("MoneyValue Value Object", () => {
|
|||||||
it("should create MoneyValue from number and currency", () => {
|
it("should create MoneyValue from number and currency", () => {
|
||||||
const result = MoneyValue.create({
|
const result = MoneyValue.create({
|
||||||
amount: 100,
|
amount: 100,
|
||||||
precision: 3,
|
scale: 3,
|
||||||
currencyCode: 'EUR'
|
currencyCode: "EUR",
|
||||||
});
|
});
|
||||||
expect(result.isSuccess).toBe(true);
|
expect(result.isSuccess).toBe(true);
|
||||||
|
|
||||||
@ -58,8 +58,8 @@ describe("MoneyValue Value Object", () => {
|
|||||||
it("should create MoneyValue from string and currency", () => {
|
it("should create MoneyValue from string and currency", () => {
|
||||||
const result = MoneyValue.create({
|
const result = MoneyValue.create({
|
||||||
amount: "12345",
|
amount: "12345",
|
||||||
precision: 2,
|
scale: 2,
|
||||||
currencyCode: 'USD'
|
currencyCode: "USD",
|
||||||
});
|
});
|
||||||
expect(result.isSuccess).toBe(true);
|
expect(result.isSuccess).toBe(true);
|
||||||
|
|
||||||
@ -73,8 +73,8 @@ describe("MoneyValue Value Object", () => {
|
|||||||
it("should fail to create MoneyValue with invalid amount", () => {
|
it("should fail to create MoneyValue with invalid amount", () => {
|
||||||
const result = MoneyValue.create({
|
const result = MoneyValue.create({
|
||||||
amount: "invalid",
|
amount: "invalid",
|
||||||
precision: 2,
|
scale: 2,
|
||||||
currencyCode: 'USD'
|
currencyCode: "USD",
|
||||||
});
|
});
|
||||||
expect(result.isFailure).toBe(true);
|
expect(result.isFailure).toBe(true);
|
||||||
});
|
});
|
||||||
@ -96,12 +96,12 @@ describe("MoneyValue Value Object", () => {
|
|||||||
|
|
||||||
// Prueba la verificación de valor cero.
|
// Prueba la verificación de valor cero.
|
||||||
it("Should check if value is zero", () => {
|
it("Should check if value is zero", () => {
|
||||||
const zeroMoneyValue = MoneyValue.create(({
|
const zeroMoneyValue = MoneyValue.create({
|
||||||
amount: 0,
|
amount: 0,
|
||||||
})).object;
|
}).object;
|
||||||
const nonZeroMoneyValue = MoneyValue.create(({
|
const nonZeroMoneyValue = MoneyValue.create({
|
||||||
amount: 50,
|
amount: 50,
|
||||||
})).object;
|
}).object;
|
||||||
|
|
||||||
expect(zeroMoneyValue.isZero()).toBe(true);
|
expect(zeroMoneyValue.isZero()).toBe(true);
|
||||||
expect(nonZeroMoneyValue.isZero()).toBe(false);
|
expect(nonZeroMoneyValue.isZero()).toBe(false);
|
||||||
|
|||||||
@ -21,7 +21,7 @@ export const defaultMoneyValueOptions: IMoneyValueOptions = {
|
|||||||
|
|
||||||
export interface MoneyValueObject {
|
export interface MoneyValueObject {
|
||||||
amount: number;
|
amount: number;
|
||||||
precision: number;
|
scale: number;
|
||||||
currency_code: string;
|
currency_code: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,13 +39,13 @@ export { RoundingMode };
|
|||||||
export interface IMoneyValueProps {
|
export interface IMoneyValueProps {
|
||||||
amount: NullOr<number | string>;
|
amount: NullOr<number | string>;
|
||||||
currencyCode?: string;
|
currencyCode?: string;
|
||||||
precision?: number;
|
scale?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultMoneyValueProps = {
|
const defaultMoneyValueProps = {
|
||||||
amount: 0,
|
amount: 0,
|
||||||
currencyCode: CurrencyData.DEFAULT_CURRENCY_CODE,
|
currencyCode: CurrencyData.DEFAULT_CURRENCY_CODE,
|
||||||
precision: 2,
|
scale: 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
interface IMoneyValue {
|
interface IMoneyValue {
|
||||||
@ -59,8 +59,8 @@ interface IMoneyValue {
|
|||||||
getAmount(): number;
|
getAmount(): number;
|
||||||
getCurrency(): CurrencyData;
|
getCurrency(): CurrencyData;
|
||||||
getLocale(): string;
|
getLocale(): string;
|
||||||
getPrecision(): number;
|
getScale(): number;
|
||||||
convertPrecision(newPrecision: number, roundingMode?: RoundingMode): MoneyValue;
|
convertScale(newScale: number, roundingMode?: RoundingMode): MoneyValue;
|
||||||
|
|
||||||
add(addend: MoneyValue): MoneyValue;
|
add(addend: MoneyValue): MoneyValue;
|
||||||
subtract(subtrahend: MoneyValue): MoneyValue;
|
subtract(subtrahend: MoneyValue): MoneyValue;
|
||||||
@ -88,7 +88,7 @@ interface IMoneyValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class MoneyValue extends ValueObject<Dinero> implements IMoneyValue {
|
export class MoneyValue extends ValueObject<Dinero> implements IMoneyValue {
|
||||||
public static readonly DEFAULT_PRECISION = defaultMoneyValueProps.precision;
|
public static readonly DEFAULT_SCALE = defaultMoneyValueProps.scale;
|
||||||
public static readonly DEFAULT_CURRENCY_CODE = defaultMoneyValueProps.currencyCode;
|
public static readonly DEFAULT_CURRENCY_CODE = defaultMoneyValueProps.currencyCode;
|
||||||
|
|
||||||
private static readonly MIN_VALUE = Number.MIN_VALUE;
|
private static readonly MIN_VALUE = Number.MIN_VALUE;
|
||||||
@ -116,15 +116,15 @@ export class MoneyValue extends ValueObject<Dinero> implements IMoneyValue {
|
|||||||
|
|
||||||
protected static getMonetaryValueInfo(amount: string): [string, number] {
|
protected static getMonetaryValueInfo(amount: string): [string, number] {
|
||||||
// Divide la cadena de entrada en dos partes: valor y precisión
|
// Divide la cadena de entrada en dos partes: valor y precisión
|
||||||
const [valuePart, precisionPart] = amount.split(".");
|
const [valuePart, scalePart] = amount.split(".");
|
||||||
|
|
||||||
// Calcula la precisión utilizada
|
// Calcula la precisión utilizada
|
||||||
const precision = precisionPart ? precisionPart.length : 0;
|
const scale = scalePart ? scalePart.length : 0;
|
||||||
|
|
||||||
// Elimina cualquier carácter no numérico de la parte del valor y concaténalo
|
// Elimina cualquier carácter no numérico de la parte del valor y concaténalo
|
||||||
const sanitizedValue = (valuePart + precisionPart).replace(/[^0-9]/g, "");
|
const sanitizedValue = (valuePart + scalePart).replace(/[^0-9]/g, "");
|
||||||
|
|
||||||
return [sanitizedValue, precision];
|
return [sanitizedValue, scale];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static create(
|
public static create(
|
||||||
@ -138,7 +138,7 @@ export class MoneyValue extends ValueObject<Dinero> implements IMoneyValue {
|
|||||||
const {
|
const {
|
||||||
amount = defaultMoneyValueProps.amount,
|
amount = defaultMoneyValueProps.amount,
|
||||||
currencyCode = defaultMoneyValueProps.currencyCode,
|
currencyCode = defaultMoneyValueProps.currencyCode,
|
||||||
precision = defaultMoneyValueProps.precision,
|
scale = defaultMoneyValueProps.scale,
|
||||||
} = props || {};
|
} = props || {};
|
||||||
|
|
||||||
const validationResult = MoneyValue.validate(amount, options);
|
const validationResult = MoneyValue.validate(amount, options);
|
||||||
@ -153,7 +153,7 @@ export class MoneyValue extends ValueObject<Dinero> implements IMoneyValue {
|
|||||||
const prop = DineroFactory({
|
const prop = DineroFactory({
|
||||||
amount: !isNull(_amount) ? Number(_amount) : options.defaultValue,
|
amount: !isNull(_amount) ? Number(_amount) : options.defaultValue,
|
||||||
currency: _currency as Currency,
|
currency: _currency as Currency,
|
||||||
precision,
|
precision: scale,
|
||||||
}).setLocale(options.locale);
|
}).setLocale(options.locale);
|
||||||
|
|
||||||
return Result.ok<MoneyValue>(new this(prop, isNull(_amount), options));
|
return Result.ok<MoneyValue>(new this(prop, isNull(_amount), options));
|
||||||
@ -175,7 +175,7 @@ export class MoneyValue extends ValueObject<Dinero> implements IMoneyValue {
|
|||||||
return Result.ok<MoneyValue>(new MoneyValue(dinero, false, defaultMoneyValueOptions));
|
return Result.ok<MoneyValue>(new MoneyValue(dinero, false, defaultMoneyValueOptions));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static normalizePrecision(objects: ReadonlyArray<MoneyValue>): MoneyValue[] {
|
public static normalizeScale(objects: ReadonlyArray<MoneyValue>): MoneyValue[] {
|
||||||
return DineroFactory.normalizePrecision(objects.map((object) => object.props)).map(
|
return DineroFactory.normalizePrecision(objects.map((object) => object.props)).map(
|
||||||
(dinero) => MoneyValue.createFromDinero(dinero).object
|
(dinero) => MoneyValue.createFromDinero(dinero).object
|
||||||
);
|
);
|
||||||
@ -225,13 +225,12 @@ export class MoneyValue extends ValueObject<Dinero> implements IMoneyValue {
|
|||||||
return this.props.getAmount();
|
return this.props.getAmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public getPrecision(): number {
|
public getScale(): number {
|
||||||
return this.props.getPrecision();
|
return this.props.getPrecision();
|
||||||
}
|
}
|
||||||
|
|
||||||
public convertPrecision(newPrecision: number, roundingMode?: RoundingMode): MoneyValue {
|
public convertScale(newScale: number, roundingMode?: RoundingMode): MoneyValue {
|
||||||
return MoneyValue.createFromDinero(this.props.convertPrecision(newPrecision, roundingMode))
|
return MoneyValue.createFromDinero(this.props.convertPrecision(newScale, roundingMode)).object;
|
||||||
.object;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCurrency(): CurrencyData {
|
public getCurrency(): CurrencyData {
|
||||||
@ -322,7 +321,7 @@ export class MoneyValue extends ValueObject<Dinero> implements IMoneyValue {
|
|||||||
const obj = this.props.toObject();
|
const obj = this.props.toObject();
|
||||||
return {
|
return {
|
||||||
amount: obj.amount,
|
amount: obj.amount,
|
||||||
precision: obj.precision,
|
scale: obj.precision,
|
||||||
currency_code: String(obj.currency),
|
currency_code: String(obj.currency),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,22 +5,22 @@ import { Result } from "./Result";
|
|||||||
export interface IUnitPriceProps {
|
export interface IUnitPriceProps {
|
||||||
amount: NullOr<number | string>;
|
amount: NullOr<number | string>;
|
||||||
currencyCode?: string;
|
currencyCode?: string;
|
||||||
precision: number;
|
scale: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UnitPrice extends MoneyValue {
|
export class UnitPrice extends MoneyValue {
|
||||||
public static create(props: IUnitPriceProps) {
|
public static create(props: IUnitPriceProps) {
|
||||||
const { amount, currencyCode, precision = 4 } = props;
|
const { amount, currencyCode, scale = 4 } = props;
|
||||||
const _unitPriceOrError = MoneyValue.create({
|
const _unitPriceOrError = MoneyValue.create({
|
||||||
amount,
|
amount,
|
||||||
currencyCode,
|
currencyCode,
|
||||||
precision,
|
scale,
|
||||||
});
|
});
|
||||||
if (_unitPriceOrError.isFailure) {
|
if (_unitPriceOrError.isFailure) {
|
||||||
return _unitPriceOrError;
|
return _unitPriceOrError;
|
||||||
}
|
}
|
||||||
|
|
||||||
const _unitPrice = _unitPriceOrError.object.convertPrecision(4);
|
const _unitPrice = _unitPriceOrError.object.convertScale(4);
|
||||||
|
|
||||||
return Result.ok<UnitPrice>(_unitPrice);
|
return Result.ok<UnitPrice>(_unitPrice);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,7 +60,7 @@
|
|||||||
"number.integer": "{{#label}}: debe ser un número entero",
|
"number.integer": "{{#label}}: debe ser un número entero",
|
||||||
"number.negative": "{{#label}}: debe ser un número negativo",
|
"number.negative": "{{#label}}: debe ser un número negativo",
|
||||||
"number.positive": "{{#label}}: debe ser un número positivo",
|
"number.positive": "{{#label}}: debe ser un número positivo",
|
||||||
"number.precision": "{{#label}}: no debe tener mas de {{limit}} decimales",
|
"number.scale": "{{#label}}: no debe tener mas de {{limit}} decimales",
|
||||||
"number.ref": "{{#label}}: referencia a \"{{ref}}\" que no es un número",
|
"number.ref": "{{#label}}: referencia a \"{{ref}}\" que no es un número",
|
||||||
"number.multiple": "{{#label}}: debe ser un múltiplo de {{multiple}}",
|
"number.multiple": "{{#label}}: debe ser un múltiplo de {{multiple}}",
|
||||||
"string.base": "{{#label}}: debe ser una cadena de texto",
|
"string.base": "{{#label}}: debe ser una cadena de texto",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
export interface IListDealers_Response_DTO {
|
export interface IListDealers_Response_DTO {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
language: string;
|
lang_code: string;
|
||||||
status: string;
|
status: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,18 +51,18 @@ export function ensureUpdateQuote_Request_DTOIsValid(quoteDTO: IUpdateQuote_Requ
|
|||||||
|
|
||||||
subtotal_price: Joi.object({
|
subtotal_price: Joi.object({
|
||||||
amount: Joi.number(),
|
amount: Joi.number(),
|
||||||
precision: Joi.number(),
|
scale: Joi.number(),
|
||||||
currency_code: Joi.string(),
|
currency_code: Joi.string(),
|
||||||
}).unknown(),
|
}).unknown(),
|
||||||
|
|
||||||
discount: Joi.object({
|
discount: Joi.object({
|
||||||
amount: Joi.number(),
|
amount: Joi.number(),
|
||||||
precision: Joi.number(),
|
scale: Joi.number(),
|
||||||
}).unknown(),
|
}).unknown(),
|
||||||
|
|
||||||
total_price: Joi.object({
|
total_price: Joi.object({
|
||||||
amount: Joi.number(),
|
amount: Joi.number(),
|
||||||
precision: Joi.number(),
|
scale: Joi.number(),
|
||||||
currency_code: Joi.string(),
|
currency_code: Joi.string(),
|
||||||
}).unknown(),
|
}).unknown(),
|
||||||
|
|
||||||
@ -71,26 +71,26 @@ export function ensureUpdateQuote_Request_DTOIsValid(quoteDTO: IUpdateQuote_Requ
|
|||||||
article_id: Joi.string().optional().allow(null).allow("").default(""),
|
article_id: Joi.string().optional().allow(null).allow("").default(""),
|
||||||
quantity: Joi.object({
|
quantity: Joi.object({
|
||||||
amount: Joi.number(),
|
amount: Joi.number(),
|
||||||
precision: Joi.number(),
|
scale: Joi.number(),
|
||||||
}).unknown(),
|
}).unknown(),
|
||||||
description: Joi.string(),
|
description: Joi.string(),
|
||||||
unit_price: Joi.object({
|
unit_price: Joi.object({
|
||||||
amount: Joi.number(),
|
amount: Joi.number(),
|
||||||
precision: Joi.number(),
|
scale: Joi.number(),
|
||||||
currency_code: Joi.string(),
|
currency_code: Joi.string(),
|
||||||
}).unknown(),
|
}).unknown(),
|
||||||
subtotal_price: Joi.object({
|
subtotal_price: Joi.object({
|
||||||
amount: Joi.number(),
|
amount: Joi.number(),
|
||||||
precision: Joi.number(),
|
scale: Joi.number(),
|
||||||
currency_code: Joi.string(),
|
currency_code: Joi.string(),
|
||||||
}).unknown(),
|
}).unknown(),
|
||||||
discount: Joi.object({
|
discount: Joi.object({
|
||||||
amount: Joi.number(),
|
amount: Joi.number(),
|
||||||
precision: Joi.number(),
|
scale: Joi.number(),
|
||||||
}).unknown(),
|
}).unknown(),
|
||||||
total_price: Joi.object({
|
total_price: Joi.object({
|
||||||
amount: Joi.number(),
|
amount: Joi.number(),
|
||||||
precision: Joi.number(),
|
scale: Joi.number(),
|
||||||
currency_code: Joi.string(),
|
currency_code: Joi.string(),
|
||||||
}).unknown(),
|
}).unknown(),
|
||||||
}).unknown(true)
|
}).unknown(true)
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
import { IMoney_Response_DTO } from "shared/lib/contexts/common";
|
import {
|
||||||
import { IPercentage_Response_DTO, IQuantity_Response_DTO } from "../../../../../common";
|
IMoney_Response_DTO,
|
||||||
|
IPercentage_Response_DTO,
|
||||||
|
IQuantity_Response_DTO,
|
||||||
|
} from "../../../../../common";
|
||||||
|
|
||||||
export interface IUpdateQuote_Response_DTO {
|
export interface IUpdateQuote_Response_DTO {
|
||||||
id: string;
|
id: string;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user