The AOC Framework
github logodiscord logo

BACKEND

Transforms #

Transformers are functions decorated with the @AocTransform decorator and are used to transform, for example, values or entities into other elements of different types.

Some cases could be: given an entity with two phone fields, return a single string with those fields concatenated, another case might be the calculation of a percentage over a value, etc.

When exporting spreadsheets, these transformations can be specified directly from the client for the columns.

Furthermore, they can be executed through the static method AocContext.execTransform.

Example #

When creating an export spreadsheet, we can define a column of type AocSpreadsheetColumn as follows:

  {
    header: 'Telephone numbers',
    type: 'string',
    field: null,
    transform: 'listTelephoneNumbers'
  }

See the full example at quest-client/src/app/features/schemas/customers/customer/customer-grid.component.ts

and on the server, we can register a method of a class with the decorator @AocTransform:

export class QuestTransforms {
  @AocTransform
  listTelephoneNumbers(args: AocTransformArgs<Customer>) {
    const phone1 = args.value.phone1;
    const phone2 = args.value.phone2;
    if (phone1 && phone2) {
      return `${phone1} - ${phone2}`;
    } else if (phone2) {
      return phone2;
    } else {
      return phone1 || ''; // In case both strings are empty
    }
  }
}

This method will automatically run for each cell of the Telephone numbers column, thus concatenating them with a hyphen in between if necessary.

See the full example at quest-server/src/transforms/quest-transforms.ts

Api #

Full definition in the API.

Please note, browse Issues and Discussions in Github for more information

© 2024 Atlantis of Code. All rights reserved.
All trademarks are the property of their respective owners.