.
This commit is contained in:
parent
54dc76534a
commit
54dc0a8442
@ -127,14 +127,13 @@ export const QuoteDetailsCardEditor = () => {
|
||||
|
||||
const handleInsertArticle = useCallback(
|
||||
(newArticle) => {
|
||||
console.log(newArticle);
|
||||
|
||||
fieldActions.append({
|
||||
...newArticle,
|
||||
quantity: {
|
||||
amount: 1,
|
||||
precision: Quantity.DEFAULT_PRECISION,
|
||||
},
|
||||
unit_price: newArticle.retail_price,
|
||||
});
|
||||
},
|
||||
[fieldActions]
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import { FormMoneyField, LoadingOverlay, SubmitButton } from "@/components";
|
||||
import { ErrorOverlay, FormMoneyField, LoadingOverlay, SubmitButton } from "@/components";
|
||||
import { calculateItemTotals } from "@/lib/calc";
|
||||
import { useGetIdentity } from "@/lib/hooks";
|
||||
import { useUrlId } from "@/lib/hooks/useUrlId";
|
||||
import { Badge, Button, Form, Tabs, TabsContent, TabsList, TabsTrigger } from "@/ui";
|
||||
import { IUpdateQuote_Request_DTO, MoneyValue } from "@shared/contexts";
|
||||
@ -45,12 +44,12 @@ export const QuoteEdit = () => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const quoteId = useUrlId();
|
||||
|
||||
const { data: userIdentity } = useGetIdentity();
|
||||
//const { data: userIdentity } = useGetIdentity();
|
||||
|
||||
const { useOne, useUpdate } = useQuotes();
|
||||
|
||||
const { data, status } = useOne(quoteId);
|
||||
const { mutate } = useUpdate(quoteId);
|
||||
const { mutate } = useUpdate(String(quoteId));
|
||||
|
||||
const form = useForm<QuoteDataForm>({
|
||||
mode: "onBlur",
|
||||
@ -64,11 +63,14 @@ export const QuoteEdit = () => {
|
||||
payment_method: "",
|
||||
notes: "",
|
||||
validity: "",
|
||||
subtotal: "",
|
||||
subtotal_price: "",
|
||||
items: [],
|
||||
},
|
||||
});
|
||||
|
||||
const { watch, getValues, setValue, formState } = form;
|
||||
const { isSubmitting } = formState;
|
||||
|
||||
const onSubmit: SubmitHandler<QuoteDataForm> = async (data) => {
|
||||
console.debug(JSON.stringify(data));
|
||||
|
||||
@ -89,8 +91,6 @@ export const QuoteEdit = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const { watch, getValues, setValue } = form;
|
||||
|
||||
useEffect(() => {
|
||||
const { unsubscribe } = watch((_, { name, type }) => {
|
||||
const value = getValues();
|
||||
@ -138,6 +138,14 @@ export const QuoteEdit = () => {
|
||||
return () => unsubscribe();
|
||||
}, [watch, getValues, setValue]);
|
||||
|
||||
if (isSubmitting) {
|
||||
return <LoadingOverlay />;
|
||||
}
|
||||
|
||||
if (status === "error") {
|
||||
return <ErrorOverlay errorMessage={queryError.message} />;
|
||||
}
|
||||
|
||||
if (status !== "success") {
|
||||
return <LoadingOverlay />;
|
||||
}
|
||||
|
||||
@ -62,7 +62,10 @@ export abstract class SequelizeRepository<T> implements IRepository<T> {
|
||||
|
||||
protected async _getById(modelName: string, id: UniqueID | string, params: any = {}): Promise<T> {
|
||||
const _model = this._adapter.getModel(modelName);
|
||||
return _model.findByPk(id.toString(), params);
|
||||
return _model.findByPk(id.toString(), {
|
||||
transaction: this._transaction,
|
||||
...params,
|
||||
});
|
||||
}
|
||||
|
||||
protected async _findAll(
|
||||
|
||||
@ -47,19 +47,19 @@ export class GetQuoteUseCase
|
||||
const transaction = this._adapter.startTransaction();
|
||||
const QuoteRepoBuilder = this._getQuoteRepository();
|
||||
|
||||
let Quote: Quote | null = null;
|
||||
let quote: Quote | null = null;
|
||||
|
||||
try {
|
||||
await transaction.complete(async (t) => {
|
||||
const QuoteRepo = QuoteRepoBuilder({ transaction: t });
|
||||
Quote = await QuoteRepo.getById(id);
|
||||
const quoteRepo = QuoteRepoBuilder({ transaction: t });
|
||||
quote = await quoteRepo.getById(id);
|
||||
});
|
||||
|
||||
if (!Quote) {
|
||||
if (!quote) {
|
||||
return Result.fail(UseCaseError.create(UseCaseError.NOT_FOUND_ERROR, "Quote not found"));
|
||||
}
|
||||
|
||||
return Result.ok<Quote>(Quote!);
|
||||
return Result.ok<Quote>(quote!);
|
||||
} catch (error: unknown) {
|
||||
const _error = error as IInfrastructureError;
|
||||
return Result.fail(UseCaseError.create(UseCaseError.REPOSITORY_ERROR, "Query error", _error));
|
||||
|
||||
@ -80,7 +80,7 @@ export class UpdateQuoteUseCase
|
||||
);
|
||||
}
|
||||
|
||||
// Crear usuario
|
||||
// Crear quote
|
||||
const quoteOrError = this._tryCreateQuoteInstance(quoteDTO, id, dealerId);
|
||||
|
||||
if (quoteOrError.isFailure) {
|
||||
|
||||
@ -59,7 +59,11 @@ export class QuoteRepository extends SequelizeRepository<Quote> implements IQuot
|
||||
}
|
||||
|
||||
public async getById(id: UniqueID): Promise<Quote | null> {
|
||||
const rawQuote: any = await this._getById("Quote_Model", id);
|
||||
const QuoteItem_Model: ModelDefined<any, any> = this._adapter.getModel("QuoteItem_Model");
|
||||
|
||||
const rawQuote: any = await this._getById("Quote_Model", id, {
|
||||
include: "items",
|
||||
});
|
||||
|
||||
if (!rawQuote === true) {
|
||||
return null;
|
||||
|
||||
@ -25,7 +25,12 @@ class QuoteItemMapper
|
||||
const props: IQuoteItemProps = {
|
||||
articleId: source.id_article,
|
||||
description: this.mapsValue(source, "description", Description.create),
|
||||
quantity: this.mapsValue(source, "quantity", Quantity.create),
|
||||
quantity: this.mapsValue(source, "quantity", (quantity) =>
|
||||
Quantity.create({
|
||||
amount: quantity,
|
||||
precision: Quantity.DEFAULT_PRECISION,
|
||||
})
|
||||
),
|
||||
unitPrice: this.mapsValue(source, "unit_price", (unit_price) =>
|
||||
MoneyValue.create({
|
||||
amount: unit_price,
|
||||
|
||||
@ -6,7 +6,6 @@ import {
|
||||
Measure,
|
||||
Name,
|
||||
Phone,
|
||||
Quantity,
|
||||
Result,
|
||||
UTCDateValue,
|
||||
UniqueID,
|
||||
@ -63,11 +62,11 @@ export const ensureDescriptionIsValid = (value: string): Result<boolean, Error>
|
||||
return descriptionOrError.isSuccess ? Result.ok(true) : Result.fail(descriptionOrError.error);
|
||||
};
|
||||
|
||||
export const ensureQuantityIsValid = (value: string): Result<boolean, Error> => {
|
||||
/*export const ensureQuantityIsValid = (value: string): Result<boolean, Error> => {
|
||||
const descriptionOrError = Quantity.create(value);
|
||||
|
||||
return descriptionOrError.isSuccess ? Result.ok(true) : Result.fail(descriptionOrError.error);
|
||||
};
|
||||
};*/
|
||||
|
||||
export const ensureUnitPriceIsValid = (value: any): Result<boolean, Error> => {
|
||||
const { amount, currency, precision } = value;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user