mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
shoud decrease + isLegandary
This commit is contained in:
parent
bad7c901ea
commit
b7eaf1987a
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
export class Item {
|
||||
name: string
|
||||
sellIn: number
|
||||
@ -20,19 +21,30 @@ export class GildedRose {
|
||||
this.items = items
|
||||
}
|
||||
|
||||
// est périmité ?
|
||||
// should increase quality ?
|
||||
|
||||
shouldDecreaseQuality(item: Item) {
|
||||
return (
|
||||
item.name != 'Aged Brie' &&
|
||||
item.name != 'Backstage passes to a TAFKAL80ETC concert' &&
|
||||
item.quality > 0
|
||||
)
|
||||
}
|
||||
|
||||
isLegendayProduct(item: Item) {
|
||||
return item.name === 'Sulfuras, Hand of Ragnaros'
|
||||
}
|
||||
|
||||
updateQuality() {
|
||||
this.items.forEach(item => {
|
||||
if (this.isLegendayProduct(item)) {
|
||||
return
|
||||
}
|
||||
const currentProductName = item.name
|
||||
// PART 1
|
||||
if (
|
||||
currentProductName != 'Aged Brie' &&
|
||||
currentProductName != 'Backstage passes to a TAFKAL80ETC concert'
|
||||
) {
|
||||
if (item.quality > 0) {
|
||||
if (currentProductName != 'Sulfuras, Hand of Ragnaros') {
|
||||
item.quality = item.quality - 1
|
||||
}
|
||||
}
|
||||
if (this.shouldDecreaseQuality(item)) {
|
||||
item.quality = item.quality - 1
|
||||
} else {
|
||||
if (item.quality < 50) {
|
||||
item.quality = item.quality + 1
|
||||
@ -51,17 +63,13 @@ export class GildedRose {
|
||||
}
|
||||
}
|
||||
// part 2
|
||||
if (currentProductName != 'Sulfuras, Hand of Ragnaros') {
|
||||
item.sellIn = item.sellIn - 1
|
||||
}
|
||||
item.sellIn = item.sellIn - 1
|
||||
// part 3
|
||||
if (item.sellIn < 0) {
|
||||
if (currentProductName != 'Aged Brie') {
|
||||
if (currentProductName != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if (item.quality > 0) {
|
||||
if (currentProductName != 'Sulfuras, Hand of Ragnaros') {
|
||||
item.quality = item.quality - 1
|
||||
}
|
||||
item.quality = item.quality - 1
|
||||
}
|
||||
} else {
|
||||
item.quality = item.quality - item.quality
|
||||
|
||||
Loading…
Reference in New Issue
Block a user