Update scripts

This commit is contained in:
freearhey 2025-04-29 00:18:35 +03:00
parent 37b4197fb2
commit 6244ba7adb
54 changed files with 2020 additions and 1145 deletions

View file

@ -0,0 +1,33 @@
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
}
}