mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +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 {
|
export class Item {
|
||||||
name: string
|
name: string
|
||||||
sellIn: number
|
sellIn: number
|
||||||
@ -20,19 +21,30 @@ export class GildedRose {
|
|||||||
this.items = items
|
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() {
|
updateQuality() {
|
||||||
this.items.forEach(item => {
|
this.items.forEach(item => {
|
||||||
|
if (this.isLegendayProduct(item)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const currentProductName = item.name
|
const currentProductName = item.name
|
||||||
// PART 1
|
// PART 1
|
||||||
if (
|
if (this.shouldDecreaseQuality(item)) {
|
||||||
currentProductName != 'Aged Brie' &&
|
item.quality = item.quality - 1
|
||||||
currentProductName != 'Backstage passes to a TAFKAL80ETC concert'
|
|
||||||
) {
|
|
||||||
if (item.quality > 0) {
|
|
||||||
if (currentProductName != 'Sulfuras, Hand of Ragnaros') {
|
|
||||||
item.quality = item.quality - 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (item.quality < 50) {
|
if (item.quality < 50) {
|
||||||
item.quality = item.quality + 1
|
item.quality = item.quality + 1
|
||||||
@ -51,17 +63,13 @@ export class GildedRose {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// part 2
|
// part 2
|
||||||
if (currentProductName != 'Sulfuras, Hand of Ragnaros') {
|
item.sellIn = item.sellIn - 1
|
||||||
item.sellIn = item.sellIn - 1
|
|
||||||
}
|
|
||||||
// part 3
|
// part 3
|
||||||
if (item.sellIn < 0) {
|
if (item.sellIn < 0) {
|
||||||
if (currentProductName != 'Aged Brie') {
|
if (currentProductName != 'Aged Brie') {
|
||||||
if (currentProductName != 'Backstage passes to a TAFKAL80ETC concert') {
|
if (currentProductName != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||||
if (item.quality > 0) {
|
if (item.quality > 0) {
|
||||||
if (currentProductName != 'Sulfuras, Hand of Ragnaros') {
|
item.quality = item.quality - 1
|
||||||
item.quality = item.quality - 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
item.quality = item.quality - item.quality
|
item.quality = item.quality - item.quality
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user