All files / platform/modules/salon/src/Validators UpdateSalon.js

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76                                                                                                                                                       
/* istanbul ignore file */
 
'use strict';
/** @typedef {import('@adonisjs/framework/src/Request')} Request */
/** @typedef {import('@adonisjs/framework/src/Response')} Response */
 
const ValidatorAbstract = use('C2C/Abstracts/ValidatorAbstract');
 
class ValidateUpdateSalon extends ValidatorAbstract {
  get rules() {
    const rules = {
      label:
        'string|required_without_all:logoUrl,businessName,phoneNumber,location,businessTypes,propertyIds,photos,description,listEmail',
      logoUrl: `string`,
      businessName: 'string|notEmpty|min:2|max:50',
      phoneNumber: `min:10|max:11|number`,
      location: 'object',
      businessTypes: 'array',
      'businessTypes.*': 'string|in:nail,hair,massage,spa',
      propertyIds: 'array',
      'propertyIds.*': 'string|exists:properties,id',
      photos: 'array',
      'photos.*': 'string|imageUrl',
      description: 'max:10000',
      listEmail: 'array|max:10',
      'listEmail.*.label': 'string|max:255',
      'listEmail.*.email': 'email|max:255',
    };
 
    const { location } = this.ctx.request.post();
 
    if (location) {
      rules['location.postCode'] = 'required|integer';
      rules['location.prefecture'] = 'required|string';
      rules['location.cityOrTown'] = 'required|string';
      rules['location.address'] = 'required|string';
      rules['location.building'] = 'string';
      rules['location.latLng'] = 'required|object';
      rules['location.latLng.lat'] = 'required|number';
      rules['location.latLng.lng'] = 'required|number';
 
      rules['location.area'] = 'required|object';
      rules['location.area.id'] = 'required|string';
      rules['location.area.name'] = 'required|string';
      rules['location.area.prefecture'] = 'required|object';
      rules['location.area.prefecture.id'] = 'required|string';
      rules['location.area.prefecture.code'] = 'string';
      rules['location.area.prefecture.name'] = 'required|string';
      rules['location.area.prefecture.city'] = 'required|object';
      rules['location.area.prefecture.city.id'] = 'required|string';
      rules['location.area.prefecture.city.name'] = 'required|string';
 
      rules['location.station'] = 'object';
      rules['location.station.stationId'] = 'string|max:50';
      rules['location.station.stationName'] = 'string|max:200';
      rules['location.station.lineId'] = 'string|max:50';
      rules['location.station.lineName'] = 'string|max:200';
      rules['location.station.walkingTime'] = 'integer|above:-1';
      rules['location.station.description'] = 'string|max:500';
 
      rules['location.isPrivate'] = 'boolean';
    }
 
    return rules;
  }
 
  get sanitizationRules() {
    return {
      'location.isPrivate': 'to_boolean',
      listEmail: 'to_array',
    };
  }
}
 
module.exports = ValidateUpdateSalon;