🚨 Announcing Vendure v2 Beta

Calculated

Calculated

Used to define calculated entity getters. The decorator simply attaches an array of “calculated” property names to the entity’s prototype. This array is then used by the {@link CalculatedPropertySubscriber} to transfer the getter function from the prototype to the entity instance.

Signature

function Calculated(queryInstruction?: CalculatedColumnQueryInstruction): MethodDecorator

Parameters

queryInstruction

CalculatedColumnQueryInstruction

Optional metadata used to tell the ListQueryBuilder & Relations decorator how to deal with calculated columns when sorting, filtering and deriving required relations from GraphQL operations.

Signature

interface CalculatedColumnQueryInstruction {
  relations?: string[];
  query?: (qb: SelectQueryBuilder<any>) => void;
  expression?: string;
}

Members

relations

property
type:
string[]
If the calculated property depends on one or more relations being present on the entity (e.g. an Order entity calculating the totalQuantity by adding up the quantities of each OrderLine), then those relations should be defined here.

query

property
type:
(qb: SelectQueryBuilder<any>) => void

expression

property
type:
string