forked from Yara724/api
Fixed daqi being enforced on REPAIR
This commit is contained in:
@@ -33,6 +33,20 @@ describe("getExpertReplyPricingValidationError", () => {
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("accepts a repair line without daghi", () => {
|
||||
expect(
|
||||
getExpertReplyPricingValidationError([
|
||||
{
|
||||
partId: 201,
|
||||
typeOfDamage: TypeOfDamage.Repair,
|
||||
price: "10000",
|
||||
salary: "0",
|
||||
totalPayment: "10000",
|
||||
},
|
||||
]),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("rejects a repair line without a price", () => {
|
||||
expect(
|
||||
getExpertReplyPricingValidationError([
|
||||
|
||||
@@ -42,9 +42,11 @@ export function getExpertReplyPricingValidationError(
|
||||
return `${label} requires typeOfDamage to be either '${TypeOfDamage.Repair}' or '${TypeOfDamage.Change}'.`;
|
||||
}
|
||||
|
||||
const daghi = part.daghi;
|
||||
if (
|
||||
!part.daghi ||
|
||||
!Object.values(DaghiOption).includes(part.daghi.option as DaghiOption)
|
||||
part.typeOfDamage === TypeOfDamage.Change &&
|
||||
(!daghi ||
|
||||
!Object.values(DaghiOption).includes(daghi.option as DaghiOption))
|
||||
) {
|
||||
return `${label} requires a valid daghi option.`;
|
||||
}
|
||||
@@ -52,7 +54,7 @@ export function getExpertReplyPricingValidationError(
|
||||
const price = parseMoneyAmountToman(part.price);
|
||||
const salary = parseMoneyAmountToman(part.salary);
|
||||
const totalPayment = parseMoneyAmountToman(part.totalPayment);
|
||||
const daghiPrice = parseMoneyAmountToman(part.daghi.price);
|
||||
const daghiPrice = parseMoneyAmountToman(daghi?.price);
|
||||
const hasPrice =
|
||||
part.price != null &&
|
||||
(typeof part.price !== "string" || part.price.trim() !== "");
|
||||
@@ -80,7 +82,7 @@ export function getExpertReplyPricingValidationError(
|
||||
}
|
||||
|
||||
if (
|
||||
part.daghi.option === DaghiOption.RECYCLED_PARTS_VALUE &&
|
||||
daghi?.option === DaghiOption.RECYCLED_PARTS_VALUE &&
|
||||
(daghiPrice === null ||
|
||||
daghiPrice < REPAIR_LINE_AMOUNT_TOMAN.MIN ||
|
||||
daghiPrice > REPAIR_LINE_AMOUNT_TOMAN.MAX)
|
||||
|
||||
Reference in New Issue
Block a user