Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 1x 1x 18x 18x 18x 18x 18x 9x 18x 18x 6x 18x 24x 1x | 'use strict';
const ValidatorAbstract = use('C2C/Abstracts/ValidatorAbstract');
const Config = use('Config');
class SaveStaff extends ValidatorAbstract {
get rules() {
const { request } = this.ctx;
const customerId = request.params.customerId;
const ageLimit = Config.get('modules.customer.general.ageLimit');
const rules = {
name: 'required|string|max:255',
phoneNumber: `string|max:30|unique:customers,phoneNumber,id,${customerId}`,
email: `email|max:255|unique:customers,email,id,${customerId}`,
birthday: `dateFormat:YYYY-MM-DD|beforeOffsetOf:${ageLimit},years`,
gender: 'integer',
active: 'boolean',
location: 'object',
'location.postCode': 'integer',
'location.prefecture': 'string',
'location.cityOrTown': 'string',
'location.address': 'string',
avatar: 'string|imageUrl',
};
if (!customerId) {
rules.phoneNumber = `required|${rules.phoneNumber}`;
}
const { location } = request.post();
if (location && (location.prefecture || location.cityOrTown)) {
rules['location.postCode'] = 'required|integer';
}
return rules;
}
get sanitizationRules() {
return {
name: 'trim',
email: 'normalize_email',
phoneNumber: 'trim',
gender: 'to_int',
active: 'to_boolean',
};
}
}
module.exports = SaveStaff;
|