🚨 Announcing Vendure v2 Beta

TranslatableSaver

TranslatableSaver

A helper which contains methods for creating and updating entities which implement the Translatable interface.

Example

export class MyService {
  constructor(private translatableSaver: TranslatableSaver) {}

  async create(ctx: RequestContext, input: CreateFacetInput): Promise<Translated<Facet>> {
    const facet = await this.translatableSaver.create({
      ctx,
      input,
      entityType: Facet,
      translationType: FacetTranslation,
      beforeSave: async f => {
          f.code = await this.ensureUniqueCode(ctx, f.code);
      },
    });
    return facet;
  }

  // ...
}

Signature

class TranslatableSaver {
  constructor(connection: TransactionalConnection)
  async create(options: CreateTranslatableOptions<T>) => Promise<T>;
  async update(options: UpdateTranslatableOptions<T>) => Promise<T>;
}

Members

constructor

method
type:
(connection: TransactionalConnection) => TranslatableSaver

create

async method
type:
(options: CreateTranslatableOptions<T>) => Promise<T>
Create a translatable entity, including creating any translation entities according to the translations array.

update

async method
type:
(options: UpdateTranslatableOptions<T>) => Promise<T>
Update a translatable entity. Performs a diff of the translations array in order to perform the correct operation on the translations.