-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from yusufshakeel/dev
v0.8.8
- Loading branch information
Showing
19 changed files
with
249 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict'; | ||
|
||
const { ERROR_CONSTANTS } = require('../constants.js'); | ||
const ValidationError = require('../error/validation-error.js'); | ||
|
||
const isOfType = (variable, type) => typeof variable === type; | ||
|
||
function couponConfigValidator(config) { | ||
const { verbose, logPerformance, maxNumberOfCouponsToGenerate } = config; | ||
|
||
if (verbose && !isOfType(verbose, 'boolean')) { | ||
throw new ValidationError({ | ||
message: `Coupon engine configuration field 'verbose' must be of type boolean.`, | ||
errors: [ | ||
{ | ||
type: ERROR_CONSTANTS.COUPONJS_COUPON_ENGINE_CONFIGURATION_ERROR.type, | ||
field: 'verbose', | ||
message: `Coupon engine configuration field 'verbose' must be of type boolean.` | ||
} | ||
] | ||
}); | ||
} | ||
|
||
if (logPerformance && !isOfType(logPerformance, 'boolean')) { | ||
throw new ValidationError({ | ||
message: `Coupon engine configuration field 'logPerformance' must be of type boolean.`, | ||
errors: [ | ||
{ | ||
type: ERROR_CONSTANTS.COUPONJS_COUPON_ENGINE_CONFIGURATION_ERROR.type, | ||
field: 'logPerformance', | ||
message: `Coupon engine configuration field 'logPerformance' must be of type boolean.` | ||
} | ||
] | ||
}); | ||
} | ||
|
||
if (maxNumberOfCouponsToGenerate && !Number.isInteger(maxNumberOfCouponsToGenerate)) { | ||
throw new ValidationError({ | ||
message: `Coupon engine configuration field 'maxNumberOfCouponsToGenerate' must be of type integer.`, | ||
errors: [ | ||
{ | ||
type: ERROR_CONSTANTS.COUPONJS_COUPON_ENGINE_CONFIGURATION_ERROR.type, | ||
field: 'maxNumberOfCouponsToGenerate', | ||
message: `Coupon engine configuration field 'maxNumberOfCouponsToGenerate' must be of type integer.` | ||
} | ||
] | ||
}); | ||
} | ||
|
||
if (maxNumberOfCouponsToGenerate < 1) { | ||
throw new ValidationError({ | ||
message: `Coupon engine configuration field 'maxNumberOfCouponsToGenerate' must be greater than 0.`, | ||
errors: [ | ||
{ | ||
type: ERROR_CONSTANTS.COUPONJS_COUPON_ENGINE_CONFIGURATION_ERROR.type, | ||
field: 'maxNumberOfCouponsToGenerate', | ||
message: `Coupon engine configuration field 'maxNumberOfCouponsToGenerate' must be greater than 0.` | ||
} | ||
] | ||
}); | ||
} | ||
} | ||
|
||
module.exports = { couponConfigValidator }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.