How to use the @vendure/core.RequestContext.fromObject function in @vendure/core

To help you get started, we’ve selected a few @vendure/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vendure-ecommerce / vendure / packages / elasticsearch-plugin / src / indexer.controller.ts View on Github external
updateProductOrVariant({
        ctx: rawContext,
        productId,
        variantId,
    }: UpdateProductOrVariantMessage['data']): Observable {
        const ctx = RequestContext.fromObject(rawContext);
        return defer(async () => {
            if (productId) {
                await this.updateProduct(ctx, productId);
            } else if (variantId) {
                await this.updateProductVariant(ctx, variantId);
            }
            return true;
        });
    }
github vendure-ecommerce / vendure / packages / elasticsearch-plugin / src / indexer.controller.ts View on Github external
reindex({ ctx: rawContext }: ReindexMessage['data']): Observable {
        const ctx = RequestContext.fromObject(rawContext);
        const { batchSize } = this.options;

        return new Observable(observer => {
            (async () => {
                const timeStart = Date.now();
                const qb = this.getSearchIndexQueryBuilder();
                const count = await qb.where('variants__product.deletedAt IS NULL').getCount();
                Logger.verbose(`Reindexing ${count} ProductVariants`, loggerCtx);

                const batches = Math.ceil(count / batchSize);
                let variantsInProduct: ProductVariant[] = [];

                for (let i = 0; i < batches; i++) {
                    Logger.verbose(`Processing batch ${i + 1} of ${batches}`, loggerCtx);

                    const variants = await this.getBatch(ctx, qb, i);
github vendure-ecommerce / vendure / packages / elasticsearch-plugin / src / indexer.controller.ts View on Github external
updateVariantsById({
        ctx: rawContext,
        ids,
    }: UpdateVariantsByIdMessage['data']): Observable {
        const ctx = RequestContext.fromObject(rawContext);
        const { batchSize } = this.options;

        return new Observable(observer => {
            (async () => {
                const timeStart = Date.now();

                if (ids.length) {
                    const batches = Math.ceil(ids.length / batchSize);
                    Logger.verbose(`Updating ${ids.length} variants...`);

                    let variantsInProduct: ProductVariant[] = [];

                    for (let i = 0; i < batches; i++) {
                        const begin = i * batchSize;
                        const end = begin + batchSize;
                        Logger.verbose(`Updating ids from index ${begin} to ${end}`);