
export default {

    formatFormData: function ({ data, rules }) {

        rules.forEach(rule => {
            if (rule.field in data) {
                let value = data[rule.field];
                if (rule.dataRule && rule.dataRule.type == "integer") {
                    data[rule.field] = parseInt(value);
                }
                if (rule.dataRule && rule.dataRule.type == "timestamp") {
                    data[rule.field] = parseInt(new Date(data[rule.field]).getTime() / 1000);
                }
            }
        });

    },


    validateForm : function ({ form }) {


        return new Promise((resolve, reject) => {

            form.validate(a => { 
                let count = 0;
                if (a) {
                    for (let name in a) {
                        a[name];
                        count++;
                    }
                }

                if (count > 0) {
                    reject(count);
                } else {
                    resolve();
                }
            });



        });
    }

}