Moved aged-brie-behavior to its own folder, use config.maxQuality

This commit is contained in:
Arno Chauveau 2025-07-24 15:08:37 +02:00
parent ef9c478e7c
commit 6c4e56174c
2 changed files with 6 additions and 7 deletions

View File

@ -1,23 +1,22 @@
import { config } from "@app/config";
import { Item } from "@app/item"; import { Item } from "@app/item";
import { IUpdateBehavior } from "../update-behavior.interface"; import { IUpdateBehavior } from "@app/update-behaviors";
export class AgedBrieBehavior implements IUpdateBehavior { export class AgedBrieBehavior implements IUpdateBehavior {
readonly #MAX_AMOUNT = 50;
constructor(private item: Item) {} constructor(private item: Item) {}
update(): Item { update(): Item {
this.item.sellIn -= 1; const isPastSellInDay = this.item.sellIn <= 0;
const isPastSellInDay = this.item.sellIn < 0;
const amountToAdd = isPastSellInDay ? 2 : 1; const amountToAdd = isPastSellInDay ? 2 : 1;
this.item.quality = Math.min( this.item.quality = Math.min(
this.#MAX_AMOUNT, config.maxQuality,
this.item.quality + amountToAdd this.item.quality + amountToAdd
); );
this.item.sellIn -= 1;
return this.item; return this.item;
} }
} }