mirror of
https://github.com/iptv-org/iptv
synced 2026-04-19 01:09:48 -04:00
Update scripts
This commit is contained in:
@@ -1,26 +1,41 @@
|
||||
import { SubdivisionData, SubdivisionSerializedData } from '../types/subdivision'
|
||||
import { Dictionary } from '@freearhey/core'
|
||||
import { Country } from '.'
|
||||
|
||||
type SubdivisionData = {
|
||||
code: string
|
||||
name: string
|
||||
country: string
|
||||
}
|
||||
|
||||
export class Subdivision {
|
||||
code: string
|
||||
name: string
|
||||
countryCode: string
|
||||
country?: Country
|
||||
|
||||
constructor(data: SubdivisionData) {
|
||||
constructor(data?: SubdivisionData) {
|
||||
if (!data) return
|
||||
|
||||
this.code = data.code
|
||||
this.name = data.name
|
||||
this.countryCode = data.country
|
||||
}
|
||||
|
||||
withCountry(countriesGroupedByCode: Dictionary): this {
|
||||
this.country = countriesGroupedByCode.get(this.countryCode)
|
||||
withCountry(countriesKeyByCode: Dictionary): this {
|
||||
this.country = countriesKeyByCode.get(this.countryCode)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
serialize(): SubdivisionSerializedData {
|
||||
return {
|
||||
code: this.code,
|
||||
name: this.name,
|
||||
countryCode: this.code,
|
||||
country: this.country ? this.country.serialize() : undefined
|
||||
}
|
||||
}
|
||||
|
||||
deserialize(data: SubdivisionSerializedData): this {
|
||||
this.code = data.code
|
||||
this.name = data.name
|
||||
this.countryCode = data.countryCode
|
||||
this.country = data.country ? new Country().deserialize(data.country) : undefined
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user