|
|
@@ -11,7 +11,6 @@ import {
|
|
|
} from '@vendure/common/lib/generated-types';
|
|
|
import { ID, PaginatedList } from '@vendure/common/lib/shared-types';
|
|
|
import { unique } from '@vendure/common/lib/unique';
|
|
|
-import { getActiveSpan } from '@vendure/telemetry';
|
|
|
import { FindOptionsUtils, In, IsNull } from 'typeorm';
|
|
|
|
|
|
import { RequestContext } from '../../api/common/request-context';
|
|
|
@@ -77,12 +76,6 @@ export class ProductService {
|
|
|
options?: ListQueryOptions<Product>,
|
|
|
relations?: RelationPaths<Product>,
|
|
|
): Promise<PaginatedList<Translated<Product>>> {
|
|
|
- const span = getActiveSpan();
|
|
|
- span?.setAttribute('channelId', ctx.channelId.toString());
|
|
|
- span?.addEvent('channelId', {
|
|
|
- channelId: ctx.channelId.toString(),
|
|
|
- });
|
|
|
-
|
|
|
const effectiveRelations = relations || this.relations.slice();
|
|
|
const customPropertyMap: { [name: string]: string } = {};
|
|
|
const hasFacetValueIdFilter = this.listQueryBuilder.filterObjectHasProperty<ProductFilterParameter>(
|
|
|
@@ -102,9 +95,6 @@ export class ProductService {
|
|
|
customPropertyMap.sku = 'variants.sku';
|
|
|
}
|
|
|
|
|
|
- span?.setAttribute('hasFacetValueIdFilter', hasFacetValueIdFilter.toString());
|
|
|
- span?.setAttribute('hasSkuFilter', hasSkuFilter.toString());
|
|
|
-
|
|
|
return this.listQueryBuilder
|
|
|
.build(Product, options, {
|
|
|
relations: effectiveRelations,
|
|
|
@@ -118,8 +108,6 @@ export class ProductService {
|
|
|
const items = products.map(product =>
|
|
|
this.translator.translate(product, ctx, ['facetValues', ['facetValues', 'facet']]),
|
|
|
);
|
|
|
- span?.setAttribute('productsCount', products.length.toString());
|
|
|
- span?.setAttribute('totalItems', totalItems.toString());
|
|
|
return {
|
|
|
items,
|
|
|
totalItems,
|
|
|
@@ -155,10 +143,6 @@ export class ProductService {
|
|
|
productIds: ID[],
|
|
|
relations?: RelationPaths<Product>,
|
|
|
): Promise<Array<Translated<Product>>> {
|
|
|
- const span = getActiveSpan();
|
|
|
- span?.setAttribute('productIds', productIds.join(','));
|
|
|
- span?.setAttribute('channelId', ctx.channelId.toString());
|
|
|
-
|
|
|
const qb = this.connection
|
|
|
.getRepository(ctx, Product)
|
|
|
.createQueryBuilder('product')
|
|
|
@@ -172,7 +156,6 @@ export class ProductService {
|
|
|
.andWhere('channel.id = :channelId', { channelId: ctx.channelId })
|
|
|
.getMany()
|
|
|
.then(products => {
|
|
|
- span?.setAttribute('foundCount', products.length.toString());
|
|
|
return products.map(product =>
|
|
|
this.translator.translate(product, ctx, ['facetValues', ['facetValues', 'facet']]),
|
|
|
);
|
|
|
@@ -184,21 +167,14 @@ export class ProductService {
|
|
|
* Returns all Channels to which the Product is assigned.
|
|
|
*/
|
|
|
async getProductChannels(ctx: RequestContext, productId: ID): Promise<Channel[]> {
|
|
|
- const span = getActiveSpan();
|
|
|
- span?.setAttribute('productId', productId.toString());
|
|
|
-
|
|
|
const product = await this.connection.getEntityOrThrow(ctx, Product, productId, {
|
|
|
relations: ['channels'],
|
|
|
channelId: ctx.channelId,
|
|
|
});
|
|
|
- span?.setAttribute('channelsCount', product.channels.length.toString());
|
|
|
return product.channels;
|
|
|
}
|
|
|
|
|
|
getFacetValuesForProduct(ctx: RequestContext, productId: ID): Promise<Array<Translated<FacetValue>>> {
|
|
|
- const span = getActiveSpan();
|
|
|
- span?.setAttribute('productId', productId.toString());
|
|
|
-
|
|
|
return this.connection
|
|
|
.getRepository(ctx, Product)
|
|
|
.findOne({
|
|
|
@@ -207,11 +183,8 @@ export class ProductService {
|
|
|
})
|
|
|
.then(product => {
|
|
|
if (!product) {
|
|
|
- span?.setAttribute('found', 'false');
|
|
|
return [];
|
|
|
}
|
|
|
- span?.setAttribute('found', 'true');
|
|
|
- span?.setAttribute('facetValuesCount', product.facetValues.length.toString());
|
|
|
return product.facetValues.map(o => this.translator.translate(o, ctx, ['facet']));
|
|
|
});
|
|
|
}
|
|
|
@@ -221,10 +194,6 @@ export class ProductService {
|
|
|
slug: string,
|
|
|
relations?: RelationPaths<Product>,
|
|
|
): Promise<Translated<Product> | undefined> {
|
|
|
- const span = getActiveSpan();
|
|
|
- span?.setAttribute('slug', slug);
|
|
|
- span?.setAttribute('channelId', ctx.channelId.toString());
|
|
|
-
|
|
|
const qb = this.connection.getRepository(ctx, Product).createQueryBuilder('product');
|
|
|
const translationQb = this.connection
|
|
|
.getRepository(ctx, ProductTranslation)
|
|
|
@@ -248,18 +217,13 @@ export class ProductService {
|
|
|
// all the joins etc.
|
|
|
const result = await qb.getRawOne();
|
|
|
if (result) {
|
|
|
- span?.setAttribute('found', 'true');
|
|
|
return this.findOne(ctx, result.id, relations);
|
|
|
} else {
|
|
|
- span?.setAttribute('found', 'false');
|
|
|
return undefined;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
async create(ctx: RequestContext, input: CreateProductInput): Promise<Translated<Product>> {
|
|
|
- const span = getActiveSpan();
|
|
|
- span?.setAttribute('productName', input.translations?.[0]?.name || 'unnamed');
|
|
|
-
|
|
|
await this.slugValidator.validateSlugs(ctx, input, ProductTranslation);
|
|
|
const product = await this.translatableSaver.create({
|
|
|
ctx,
|
|
|
@@ -278,14 +242,10 @@ export class ProductService {
|
|
|
await this.assetService.updateEntityAssets(ctx, product, input);
|
|
|
await this.eventBus.publish(new ProductEvent(ctx, product, 'created', input));
|
|
|
|
|
|
- span?.setAttribute('newProductId', product.id.toString());
|
|
|
return assertFound(this.findOne(ctx, product.id));
|
|
|
}
|
|
|
|
|
|
async update(ctx: RequestContext, input: UpdateProductInput): Promise<Translated<Product>> {
|
|
|
- const span = getActiveSpan();
|
|
|
- span?.setAttribute('productId', input.id.toString());
|
|
|
-
|
|
|
const product = await this.connection.getEntityOrThrow(ctx, Product, input.id, {
|
|
|
channelId: ctx.channelId,
|
|
|
relations: ['facetValues', 'facetValues.channels'],
|
|
|
@@ -317,9 +277,6 @@ export class ProductService {
|
|
|
}
|
|
|
|
|
|
async softDelete(ctx: RequestContext, productId: ID): Promise<DeletionResponse> {
|
|
|
- const span = getActiveSpan();
|
|
|
- span?.setAttribute('productId', productId.toString());
|
|
|
-
|
|
|
const product = await this.connection.getEntityOrThrow(ctx, Product, productId, {
|
|
|
relationLoadStrategy: 'query',
|
|
|
loadEagerRelations: false,
|
|
|
@@ -351,7 +308,6 @@ export class ProductService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- span?.setAttribute('result', DeletionResult.DELETED);
|
|
|
return {
|
|
|
result: DeletionResult.DELETED,
|
|
|
};
|
|
|
@@ -369,11 +325,6 @@ export class ProductService {
|
|
|
ctx: RequestContext,
|
|
|
input: AssignProductsToChannelInput,
|
|
|
): Promise<Array<Translated<Product>>> {
|
|
|
- const span = getActiveSpan();
|
|
|
- span?.setAttribute('productIds', input.productIds.join(','));
|
|
|
- span?.setAttribute('channelId', input.channelId.toString());
|
|
|
- span?.setAttribute('productsCount', input.productIds.length.toString());
|
|
|
-
|
|
|
const productsWithVariants = await this.connection.getRepository(ctx, Product).find({
|
|
|
where: { id: In(input.productIds) },
|
|
|
relations: ['variants', 'assets'],
|
|
|
@@ -405,11 +356,6 @@ export class ProductService {
|
|
|
ctx: RequestContext,
|
|
|
input: RemoveProductsFromChannelInput,
|
|
|
): Promise<Array<Translated<Product>>> {
|
|
|
- const span = getActiveSpan();
|
|
|
- span?.setAttribute('productIds', input.productIds.join(','));
|
|
|
- span?.setAttribute('channelId', input.channelId.toString());
|
|
|
- span?.setAttribute('productsCount', input.productIds.length.toString());
|
|
|
-
|
|
|
const productsWithVariants = await this.connection.getRepository(ctx, Product).find({
|
|
|
where: { id: In(input.productIds) },
|
|
|
relations: ['variants'],
|
|
|
@@ -437,10 +383,6 @@ export class ProductService {
|
|
|
productId: ID,
|
|
|
optionGroupId: ID,
|
|
|
): Promise<Translated<Product>> {
|
|
|
- const span = getActiveSpan();
|
|
|
- span?.setAttribute('productId', productId.toString());
|
|
|
- span?.setAttribute('optionGroupId', optionGroupId.toString());
|
|
|
-
|
|
|
const product = await this.getProductWithOptionGroups(ctx, productId);
|
|
|
const optionGroup = await this.connection.getRepository(ctx, ProductOptionGroup).findOne({
|
|
|
where: { id: optionGroupId },
|
|
|
@@ -476,11 +418,6 @@ export class ProductService {
|
|
|
optionGroupId: ID,
|
|
|
force?: boolean,
|
|
|
): Promise<ErrorResultUnion<RemoveOptionGroupFromProductResult, Translated<Product>>> {
|
|
|
- const span = getActiveSpan();
|
|
|
- span?.setAttribute('productId', productId.toString());
|
|
|
- span?.setAttribute('optionGroupId', optionGroupId.toString());
|
|
|
- span?.setAttribute('force', Boolean(force).toString());
|
|
|
-
|
|
|
const product = await this.getProductWithOptionGroups(ctx, productId);
|
|
|
const optionGroup = product.optionGroups.find(g => idsAreEqual(g.id, optionGroupId));
|
|
|
if (!optionGroup) {
|
|
|
@@ -526,9 +463,6 @@ export class ProductService {
|
|
|
}
|
|
|
|
|
|
private async getProductWithOptionGroups(ctx: RequestContext, productId: ID): Promise<Product> {
|
|
|
- const span = getActiveSpan();
|
|
|
- span?.setAttribute('productId', productId.toString());
|
|
|
-
|
|
|
const product = await this.connection.getRepository(ctx, Product).findOne({
|
|
|
relationLoadStrategy: 'query',
|
|
|
loadEagerRelations: false,
|
|
|
@@ -536,12 +470,8 @@ export class ProductService {
|
|
|
relations: ['optionGroups', 'variants', 'variants.options'],
|
|
|
});
|
|
|
if (!product) {
|
|
|
- span?.setAttribute('found', 'false');
|
|
|
throw new EntityNotFoundError('Product', productId);
|
|
|
}
|
|
|
- span?.setAttribute('found', 'true');
|
|
|
- span?.setAttribute('optionGroupsCount', product.optionGroups.length.toString());
|
|
|
- span?.setAttribute('variantsCount', product.variants.length.toString());
|
|
|
return product;
|
|
|
}
|
|
|
}
|