All files / src/entities draft_template.ts

100% Statements 30/30
100% Branches 0/0
66.66% Functions 2/3
100% Lines 27/27

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  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 { DraftPreviewLayer } from './draft_preview_layer.js';
import { Entity } from '../entity.js';
import { MerchiFile } from './file.js';
import { Job } from './job.js';
import { Product } from './product.js';
import { VariationField } from './variation_field.js';
import { VariationFieldsOption } from './variation_fields_option.js';
 
/**
 * Runtime type tag only. The API returns `customisationMap` as arbitrary JSON;
 * the entity layer refuses `Object` from decorator metadata, so we cannot use
 * `any` / plain object without an explicit `type` option here. A const class
 * expression is used so `noUnusedLocals` counts the symbol as used (a named
 * class referenced only from decorators can trigger TS6196).
 */
const customisationMapPropertyType = class {};
 
export class DraftTemplate extends Entity {
  protected static resourceName = 'draft_templates';
  protected static singularName = 'draftTemplate';
  protected static pluralName = 'draftTemplates';
 
  @DraftTemplate.property({type: Date})
  public archived?: Date | null;
 
  @DraftTemplate.property()
  public id?: number;
 
  @DraftTemplate.property({type: Date})
  public date?: Date | null;
 
  @DraftTemplate.property()
  public description?: string;
 
  @DraftTemplate.property()
  public name?: string;
 
  @DraftTemplate.property()
  public height?: number;
 
  @DraftTemplate.property()
  public width?: number;
 
  @DraftTemplate.property({type: MerchiFile})
  public file?: MerchiFile;
 
  @DraftTemplate.property({type: 'MerchiFile'})
  public design?: MerchiFile;
 
  @DraftTemplate.property({type: Product})
  public product?: Product | null;
 
  @DraftTemplate.property({type: Job})
  public job?: Job | null;
 
  @DraftTemplate.property({arrayType: 'VariationFieldsOption'})
  public selectedByVariationFieldOptions?: VariationFieldsOption[];
 
  @DraftTemplate.property({arrayType: 'VariationField'})
  public editedByVariationFields?: VariationField[];
 
  @DraftTemplate.property({arrayType: 'DraftPreviewLayer'})
  public draftPreviewLayers?: DraftPreviewLayer[];
 
  // Cached template customisation map -- which regions of the template
  // image are editable (text placeholders, body colour fill, print
  // area) versus preserved. Populated lazily by the backend when a
  // template is first rendered, or set manually by an operator (in
  // which case ``customisationMapSource === 'manual'`` and the auto
  // analyser leaves it alone). ``customisationMapFileId`` records the
  // ``file.id`` the cached map was generated from so the analyser
  // knows when to re-run after the template image is replaced.
  @DraftTemplate.property({type: customisationMapPropertyType})
  public customisationMap?: Record<string, unknown> | null;
 
  @DraftTemplate.property({type: String})
  public customisationMapSource?: string | null;
 
  @DraftTemplate.property({type: String})
  public customisationMapFileId?: string | null;
}