import { isLength } from 'validator' ; import { Consts , InetLocation , Messages } from '@btcp/bootcamp-entities' ; import { IValidationResult } from './interfaces/validation-result.interface' ; import { isIPv6 , isIPv4 } from 'net' ; const MIN_PASSWORD_LENGTH = Consts . MIN_PASSWORD_LENGTH ; const IP_INVALID = Messages . IP_INVALID ; ; const COUNTRY_INVALID = Messages . COUNTRY_INVALID ; const BROWSER_INVALID = Messages . BROWSER_INVALID ; const MIN_BROWSER_LENGTH = Consts . MIN_BROWSER_LENGTH ; const MIN_COUNTRY_LENGTH = Consts . MIN_COUNTRY_LENGTH ; export class AccountsHelper { public static isPassword ( password ) { return isLength ( password , MIN_PASSWORD_LENGTH ) ; } public static isPasswordMatch ( password , passwordRepeat ) { return password === passwordRepeat ; } public static isValidInetLocation ( inetLocation , validationResult ) { if ( ! isIPv6 ( inetLocation . ip ) && ! isIPv4 ( inetLocation . ip ) ) { validationResult . errors . push ( IP_INVALID ) ; validationResult . isValid = false ; } if ( ! isLength ( inetLocation . country , MIN_COUNTRY_LENGTH ) ) { validationResult . errors . push ( COUNTRY_INVALID ) ; validationResult . isValid = false ; } if ( ! isLength ( inetLocation . browser , MIN_BROWSER_LENGTH ) ) { validationResult . errors . push ( BROWSER_INVALID ) ; validationResult . isValid = false ; } } }