LeagueStats/server/app/Validators/SummonerBasicValidator.ts
zkxjzmswkwl bf29894b0c Closes #80 - "Update Search Functionality to Accommodate Riot IDs".
- Check in SummonersController per @vkaelin's comment on issue #80
- - Had to send an additional request to get account id after retrieving puuid by gameName/tagline
- `puuidFromRiotTag(name, tagline, string, region)` in SummonerEndpoint
- `summonerPuuid(puuid, region)` in SummonerEndpoint
- Modified `JaxRequest` constructor to take default parameter `riotApiPath`.
- - This is due to `JaxRequest` previously assuming the api subpath of `/lol/`. `AccountsV1` is located at `/riot/`.
- Adjusted `SummonerBasicValidator` schema to accept `-` in input.
2024-01-09 05:25:18 -07:00

43 lines
1.3 KiB
TypeScript

import { rules, schema } from '@ioc:Adonis/Core/Validator'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
export default class SummonerBasicValidator {
constructor(protected ctx: HttpContextContract) {}
/*
* Define schema to validate the "shape", "type", "formatting" and "integrity" of data.
*
* For example:
* 1. The username must be of data type string. But then also, it should
* not contain special characters or numbers.
* ```
* schema.string({}, [ rules.alpha() ])
* ```
*
* 2. The email must be of data type string, formatted as a valid
* email. But also, not used by any other user.
* ```
* schema.string({}, [
* rules.email(),
* rules.unique({ table: 'users', column: 'email' }),
* ])
* ```
*/
public schema = schema.create({
summoner: schema.string({}, [rules.regex(/^[0-9\p{L} _\.-]+$/u)]),
region: schema.string(),
})
/**
* Custom messages for validation failures. You can make use of dot notation `(.)`
* for targeting nested fields and array expressions `(*)` for targeting all
* children of an array. For example:
*
* {
* 'profile.username.required': 'Username is required',
* 'scores.*.number': 'Define scores as valid numbers'
* }
*
*/
public messages = {}
}