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