import { Context } from "../context/Context"; import { IRule } from "./interface/IRule"; /* * use https://www.npmjs.com/package/validatorjs */ import { ERuleTypes } from "./enum/ERuleTypes"; import { ActionParams } from "../action/type/ActionParams"; import { BaseRule } from "./base/BaseRule"; import { RegionChangeActionParams } from "../action/type/RegionChangeActionParams"; import { CommonRules } from "./CommonRules"; import { ChangeModuleConfigParams } from "../action/type/ChangeModuleConfigParams"; export class ChangeModuleConfigRules extends BaseRule implements IRule { constructor(params: ActionParams){ super(params); } /*@overwrite*/ public validate(rules: Array, context: Context): boolean { let passes : Array = []; rules.forEach(rule => { switch (rule) { case ERuleTypes.IS_NOT_INITIATED: passes.push(new CommonRules(this.params).isNotInited(context, this)); break; case ERuleTypes.IS_VALID_CONFIG_PARAMS: let params : ChangeModuleConfigParams = Object.assign(this.params); passes.push(this.isValidConfigParams(params)); break; } }); return this.passesOrFails(passes); } public isValidConfigParams(params: ChangeModuleConfigParams){ let rules = { 'uid':"sometimes|string", 'app_id': "sometimes|string|alpha_num", 'client_config':"sometimes", 'user': "required", }; let messages = { "string.uid":'The user identifier must be a string', "string.app_id":'The aplication identifier must be a string', "alpha_num.app_id":'The aplication identifier must be a string alpha numeric', "user":'The user information is required', }; return this.evaluate(params, rules, messages); } }