| 123456789101112131415161718192021222324252627282930313233 |
- import type ApiRequestService from '~/services/data/apiRequestService'
- export default class SubdomainValidation {
- private apiRequestService: ApiRequestService
- public constructor(apiRequestService: ApiRequestService) {
- this.apiRequestService = apiRequestService
- }
- /**
- * Le sous-domaine est valide s'il contient entre 2 et 60 caractères, et pas de caractères spéciaux
- * @param subdomain
- */
- public static isValid(subdomain: string | null): boolean {
- return (
- subdomain !== null &&
- subdomain.match(/^[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/) !== null
- )
- }
- /**
- * Returns true if the given subdomain has not been registered yet or is not reserved
- * @param subdomain
- */
- public async isAvailable(subdomain: string): Promise<boolean> {
- const subdomainAvailability: Response = await this.apiRequestService.get(
- '/api/subdomains/is_available',
- { subdomain },
- )
- // @ts-expect-error Si pas d'erreur, la réponse ici doit avoir une prop 'available'
- return subdomainAvailability && subdomainAvailability.available === true
- }
- }
|