mirror of
https://github.com/iptv-org/database.git
synced 2025-05-09 19:20:01 -04:00
Update scripts
This commit is contained in:
parent
37b4197fb2
commit
6244ba7adb
54 changed files with 2020 additions and 1145 deletions
44
scripts/models/timezone.ts
Normal file
44
scripts/models/timezone.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { Collection, Dictionary } from '@freearhey/core'
|
||||
import { TimezoneData } from '../types/timezone'
|
||||
import { Model } from './model'
|
||||
import Joi from 'joi'
|
||||
|
||||
export class Timezone extends Model {
|
||||
id: string
|
||||
utcOffset: string
|
||||
countryCodes: Collection
|
||||
|
||||
constructor(data: TimezoneData) {
|
||||
super()
|
||||
|
||||
this.id = data.id
|
||||
this.utcOffset = data.utc_offset
|
||||
this.countryCodes = new Collection(data.countries)
|
||||
}
|
||||
|
||||
hasValidCountryCodes(countriesKeyByCode: Dictionary): boolean {
|
||||
const hasInvalid = this.countryCodes.find((code: string) => countriesKeyByCode.missing(code))
|
||||
|
||||
return !hasInvalid
|
||||
}
|
||||
|
||||
data(): TimezoneData {
|
||||
return {
|
||||
id: this.id,
|
||||
utc_offset: this.utcOffset,
|
||||
countries: this.countryCodes.all()
|
||||
}
|
||||
}
|
||||
|
||||
getSchema() {
|
||||
return Joi.object({
|
||||
id: Joi.string()
|
||||
.regex(/^[a-z-_/]+$/i)
|
||||
.required(),
|
||||
utc_offset: Joi.string()
|
||||
.regex(/^(\+|-)\d{2}:\d{2}$/)
|
||||
.required(),
|
||||
countries: Joi.array().items(Joi.string().regex(/^[A-Z]{2}$/))
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue