import BaseEntity from "../../common/entities/BaseEntity"; import ValidableInterface from "../../common/interfaces/ValidableInterface"; import Image from "../../Image/entity/Image"; import Perk from "../../Perk/entity/Perk"; import SeoFields from "../../SEO/entity/SeoFields"; import PageStatus from "../enums/PageStatus"; export default abstract class Page extends BaseEntity implements ValidableInterface { protected _title: string; protected _description: string; protected _slug: string; protected _images: Array = []; protected _thumbnails: Array = []; protected _perks: Array = []; protected _about_text: string; protected _about_images: Array = []; protected _seo: SeoFields = new SeoFields(); protected _status: PageStatus = PageStatus.pageStatusUnpublished; get title(): string { return this._title; } set title(value: string) { this._title = value; } get slug(): string { return this._slug; } set slug(value: string) { this._slug = value; } get description(): string { return this._description; } set description(value: string) { this._description = value; } get thumbnails(): Array { return this._thumbnails; } set thumbnails(value: Array) { this._thumbnails = value; } get images(): Array { return this._images; } set images(value: Array) { this._images = value; } get perks(): Array { return this._perks; } set perks(value: Array) { this._perks = value; } get seo(): SeoFields { return this._seo; } set seo(value: SeoFields) { this._seo = value; } get about_text(): string { return this._about_text; } set about_text(value: string) { this._about_text = value; } get about_images(): Array { return this._about_images; } set about_images(value: Array) { this._about_images = value; } get status(): PageStatus { return this._status; } set status(value: PageStatus) { this._status = value; } isPublished(): boolean { return this._status === PageStatus.pageStatusPublished; } isUnpublished(): boolean { return this._status === PageStatus.pageStatusUnpublished; } addPerk(item: Perk) { this.perks.push(item); } isValid(): boolean { return this.invalidFields().length === 0; } invalidFields(prefix: string = ""): Array { let fields = []; !this.hasValue(this.title) && fields.push(`${prefix}title`); !this.hasValue(this.slug) && fields.push(`${prefix}slug`); !this.hasValue(this.description) && fields.push(`${prefix}description`); !this.hasValue(this.seo.title) && fields.push(`${prefix}seo__title`); !this.hasValue(this.seo.description) && fields.push(`${prefix}seo__description`); !this.hasValue(this.status) && fields.push(`${prefix}status`); this.perks.map((eachPerk, i) => fields.push(...eachPerk.invalidFields(`${prefix}perks[${i}]__`)) ); return fields; } }