| Conditions | 6 |
| Total Lines | 30 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | export default class ShopwareDiscountCampaignService { |
||
| 2 | isDiscountCampaignActive(discountCampaign) { |
||
| 3 | if (!discountCampaign) { |
||
| 4 | return false; |
||
| 5 | } |
||
| 6 | |||
| 7 | if (!discountCampaign.startDate) { |
||
| 8 | return false; |
||
| 9 | } |
||
| 10 | |||
| 11 | const now = new Date(); |
||
| 12 | |||
| 13 | if (new Date(discountCampaign.startDate) > now) { |
||
| 14 | return false; |
||
| 15 | } |
||
| 16 | |||
| 17 | if (typeof discountCampaign.endDate === 'string' && |
||
| 18 | new Date(discountCampaign.endDate) < now |
||
| 19 | ) { |
||
| 20 | return false; |
||
| 21 | } |
||
| 22 | |||
| 23 | if (typeof discountCampaign.discountAppliesForMonths === 'number' && |
||
| 24 | discountCampaign.discountAppliesForMonths === 0 |
||
| 25 | ) { |
||
| 26 | return false; |
||
| 27 | } |
||
| 28 | |||
| 29 | // discounts without end date are always valid |
||
| 30 | return true; |
||
| 31 | } |
||
| 32 | |||
| 42 |