All files / src/entities theme.ts

84.46% Statements 87/103
0% Branches 0/13
33.33% Functions 1/3
85% Lines 85/100

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268    1x 1x   1x     1x   1x 1x 1x 1x   1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x                                                   1x  
import { Component } from './component.js';
import { Domain } from './domain.js';
import { Entity } from '../entity.js';
import { MerchiFile } from './file.js';
import { InternalTag } from './internal_tag.js';
import { User } from './user.js';
import { Menu } from './menu.js';
import { Page } from './page.js';
import { ThemeStatus } from '../constants/theme_status.js';
 
export class Theme extends Entity {
  protected static resourceName = 'themes';
  protected static singularName = 'theme';
  protected static pluralName = 'themes';
 
  @Theme.property({type: Date})
  public archived?: Date | null;
 
  @Theme.property()
  public id?: number;
 
  @Theme.property()
  public foundation?: number;
 
  @Theme.property({arrayType: 'InternalTag'})
  public internalTags?: InternalTag[];
 
  @Theme.property({arrayType: 'Component'})
  public components?: Component[];
 
  @Theme.property({arrayType: 'Component'})
  public contextComponents?: Component[];
 
  @Theme.property()
  public mainCssStatus?: number;
 
  @Theme.property({type: String})
  public mainCssErrorMessage?: string | null;
 
  @Theme.property()
  public emailCssStatus?: number;
 
  @Theme.property({type: String})
  public emailCssErrorMessage?: string | null;
 
  @Theme.property()
  public name?: string;
 
  @Theme.property()
  public description?: string;
 
  @Theme.property()
  public jsBundle?: string;
 
  @Theme.property()
  public headerTemplate?: string;
 
  @Theme.property({type: String})
  public headerError?: string | null;
 
  @Theme.property()
  public headerHtml?: string;
 
  @Theme.property()
  public footerTemplate?: string;
 
  @Theme.property({type: String})
  public footerError?: string | null;
 
  @Theme.property()
  public footerHtml?: string;
 
  @Theme.property()
  public indexPageTemplate?: string;
 
  @Theme.property({type: String})
  public indexPageError?: string | null;
 
  @Theme.property()
  public indexHtml?: string;
 
  @Theme.property({arrayType: 'Menu'})
  public menus?: Menu[];
 
  @Theme.property()
  public productsPageTemplate?: string;
 
  @Theme.property({type: String})
  public productsPageError?: string | null;
 
  @Theme.property()
  public productsHtml?: string;
 
  @Theme.property({type: String})
  public domainInvitePageTemplate?: string | null;
 
  @Theme.property({type: String})
  public domainInvitePageError?: string | null;
 
  @Theme.property()
  public domainInviteHtml?: string;
 
  @Theme.property({type: String})
  public resetPasswordPageTemplate?: string | null;
 
  @Theme.property({type: String})
  public resetPasswordPageError?: string | null;
 
  @Theme.property()
  public passwordResetHtml?: string;
 
  @Theme.property({type: String})
  public passwordChangePageTemplate?: string | null;
 
  @Theme.property({type: String})
  public passwordChangePageError?: string | null;
 
  @Theme.property()
  public passwordChangeHtml?: string;
 
  @Theme.property({type: String})
  public jobDraftingPageTemplate?: string | null;
 
  @Theme.property({type: String})
  public jobDraftingPageError?: string | null;
 
  @Theme.property()
  public jobDraftingHtml?: string;
 
  @Theme.property({type: String})
  public jobQuoteRequestedPageTemplate?: string | null;
 
  @Theme.property({type: String})
  public jobQuoteRequestedPageError?: string | null;
 
  @Theme.property()
  public jobQuoteRequestedHtml?: string;
 
  @Theme.property({type: String})
  public invoicePageTemplate?: string | null;
 
  @Theme.property({type: String})
  public invoicePageError?: string | null;
 
  @Theme.property()
  public invoiceHtml?: string;
 
  @Theme.property({type: String})
  public loginPageTemplate?: string | null;
 
  @Theme.property({type: String})
  public loginPageError?: string | null;
 
  @Theme.property()
  public loginPageHtml?: string;
 
  @Theme.property({type: String})
  public errorPageTemplate?: string | null;
 
  @Theme.property({type: String})
  public errorPageError?: string | null;
 
  @Theme.property()
  public errorPageHtml?: string;
 
  @Theme.property({type: String})
  public userProfilePageTemplate?: string | null;
 
  @Theme.property({type: String})
  public userProfilePageError?: string | null;
 
  @Theme.property()
  public userProfileHtml?: string;
 
  @Theme.property({type: String})
  public productPageTemplate?: string | null;
 
  @Theme.property({type: String})
  public productPageError?: string | null;
 
  @Theme.property()
  public productHtml?: string;
 
  @Theme.property({type: String})
  public invoicePaidPageTemplate?: string | null;
 
  @Theme.property({type: String})
  public invoicePaidPageError?: string | null;
 
  @Theme.property()
  public invoicePaidHtml?: string;
 
  @Theme.property()
  public lastUpdated?: Date;
 
  @Theme.property()
  public public?: boolean;
 
  @Theme.property({type: String})
  public aiContext?: string;
 
  @Theme.property({embeddedByDefault: false, type: String})
  public mainCss?: string | null;
 
  @Theme.property({embeddedByDefault: false, type: String})
  public mainCssTemplateUsing?: string | null;
 
  @Theme.property({embeddedByDefault: false, type: String})
  public mainCssTemplateEditing?: string | null;
 
  @Theme.property({embeddedByDefault: false, type: String})
  public emailCss?: string | null;
 
  @Theme.property({embeddedByDefault: false, type: String})
  public emailCssTemplateUsing?: string | null;
 
  @Theme.property({embeddedByDefault: false, type: String})
  public emailCssTemplateEditing?: string | null;
 
  @Theme.property({arrayType: 'MerchiFile'})
  public cssImageFiles?: MerchiFile[];
 
  @Theme.property({type: MerchiFile})
  public featureImage?: MerchiFile | null;
 
  @Theme.property({type: 'Domain'})
  public domain?: Domain | null;
 
  @Theme.property({type: User})
  public author?: User | null;
 
  @Theme.property({arrayType: 'MerchiFile'})
  public images?: MerchiFile[];
 
  @Theme.property({arrayType: 'Domain'})
  public domains?: Domain[];
 
  @Theme.property({arrayType: 'Page'})
  public pages?: Page[];
 
  @Theme.property({type: Number})
  public defaultForDomainType?: number | null;
 
  public canBeActivated = () => {
    const validStatus = ThemeStatus.VALID_BUT_NOT_UPDATED;
    Iif (this.mainCssStatus === undefined || this.emailCssStatus === undefined) {
      throw new Error('status is unknown');
    }
    return this.mainCssStatus >= validStatus &&
      this.emailCssStatus >= validStatus;
  };
 
  public isActiveOnDomain = (domainId: number) => {
    const domain = this.domain;
    Iif (domain === undefined) {
      throw new Error('domain is unknown');
    }
    Iif (domain === null) {
      return false;
    }
    const activeTheme = domain.activeTheme;
    Iif (activeTheme === undefined) {
      throw new Error('activeTheme is unknown');
    }
    return domain.id == domainId && activeTheme.id === this.id;
  };
}