Skip to main content

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)
create(options: CreateTranslatableOptions<T>) => Promise<T>;
update(options: UpdateTranslatableOptions<T>) => Promise<T>;
}

constructor

method
(connection: TransactionalConnection) => TranslatableSaver

create

method
(options: CreateTranslatableOptions<T>) => Promise<T>

Create a translatable entity, including creating any translation entities according to the translations array.

update

method
(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.