You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iptv/scripts/models/subdivision.ts

43 lines
1014 B
TypeScript

7 months ago
import { SubdivisionData, SubdivisionSerializedData } from '../types/subdivision'
8 months ago
import { Dictionary } from '@freearhey/core'
import { Country } from '.'
2 years ago
export class Subdivision {
code: string
name: string
8 months ago
countryCode: string
country?: Country
7 months ago
constructor(data?: SubdivisionData) {
if (!data) return
8 months ago
this.code = data.code
this.name = data.name
this.countryCode = data.country
}
7 months ago
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
2 years ago
8 months ago
return this
2 years ago
}
}