mirror of
https://github.com/iptv-org/iptv
synced 2025-12-23 05:46:53 -05:00
Update scripts
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
import { SubdivisionData, SubdivisionSerializedData } from '../types/subdivision'
|
||||
import { Dictionary } from '@freearhey/core'
|
||||
import { Country } from '.'
|
||||
import { Dictionary, Collection } from '@freearhey/core'
|
||||
import { Country, Region } from '.'
|
||||
|
||||
export class Subdivision {
|
||||
code: string
|
||||
name: string
|
||||
countryCode: string
|
||||
country?: Country
|
||||
parentCode?: string
|
||||
regions?: Collection
|
||||
cities?: Collection
|
||||
|
||||
constructor(data?: SubdivisionData) {
|
||||
if (!data) return
|
||||
@@ -14,6 +17,7 @@ export class Subdivision {
|
||||
this.code = data.code
|
||||
this.name = data.name
|
||||
this.countryCode = data.country
|
||||
this.parentCode = data.parent || undefined
|
||||
}
|
||||
|
||||
withCountry(countriesKeyByCode: Dictionary): this {
|
||||
@@ -22,12 +26,39 @@ export class Subdivision {
|
||||
return this
|
||||
}
|
||||
|
||||
withRegions(regions: Collection): this {
|
||||
this.regions = regions.filter((region: Region) =>
|
||||
region.countryCodes.includes(this.countryCode)
|
||||
)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withCities(citiesGroupedBySubdivisionCode: Dictionary): this {
|
||||
this.cities = new Collection(citiesGroupedBySubdivisionCode.get(this.code))
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
getRegions(): Collection {
|
||||
if (!this.regions) return new Collection()
|
||||
|
||||
return this.regions
|
||||
}
|
||||
|
||||
getCities(): Collection {
|
||||
if (!this.cities) return new Collection()
|
||||
|
||||
return this.cities
|
||||
}
|
||||
|
||||
serialize(): SubdivisionSerializedData {
|
||||
return {
|
||||
code: this.code,
|
||||
name: this.name,
|
||||
countryCode: this.code,
|
||||
country: this.country ? this.country.serialize() : undefined
|
||||
countryCode: this.countryCode,
|
||||
country: this.country ? this.country.serialize() : undefined,
|
||||
parentCode: this.parentCode || null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +67,7 @@ export class Subdivision {
|
||||
this.name = data.name
|
||||
this.countryCode = data.countryCode
|
||||
this.country = data.country ? new Country().deserialize(data.country) : undefined
|
||||
this.parentCode = data.parentCode || undefined
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user