mirror of
https://github.com/iptv-org/database.git
synced 2025-05-09 19:20:01 -04:00
33 lines
1 KiB
TypeScript
33 lines
1 KiB
TypeScript
import { ValidatorProps } from '../types/validator'
|
|
import { Collection } from '@freearhey/core'
|
|
import { Validator } from './validator'
|
|
import { Country } from '../models'
|
|
import { DataLoaderData } from '../types/dataLoader'
|
|
|
|
export class CountryValidator extends Validator {
|
|
constructor(props: ValidatorProps) {
|
|
super(props)
|
|
}
|
|
|
|
validate(country: Country): Collection {
|
|
const { languagesKeyByCode }: DataLoaderData = this.data
|
|
|
|
let errors = new Collection()
|
|
|
|
const joiResults = country.getSchema().validate(country.data(), { abortEarly: false })
|
|
if (joiResults.error) {
|
|
joiResults.error.details.forEach((detail: { message: string }) => {
|
|
errors.add({ line: country.getLine(), message: `${country.code}: ${detail.message}` })
|
|
})
|
|
}
|
|
|
|
if (!country.hasValidLanguageCodes(languagesKeyByCode)) {
|
|
errors.add({
|
|
line: country.getLine(),
|
|
message: `"${country.code}" has an invalid languages "${country.languageCodes.join(';')}"`
|
|
})
|
|
}
|
|
|
|
return errors
|
|
}
|
|
}
|