Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update Relations on Stock Location update #2805

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions packages/core/src/service/services/stock-location.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@ import { ID, PaginatedList } from '@vendure/common/lib/shared-types';
import { RequestContext } from '../../api/common/request-context';
import { RelationPaths } from '../../api/decorators/relations.decorator';
import { RequestContextCacheService } from '../../cache/request-context-cache.service';
import {
EntityNotFoundError,
ForbiddenError,
UserInputError,
} from '../../common/error/errors';
import { EntityNotFoundError, ForbiddenError, UserInputError } from '../../common/error/errors';
import { ListQueryOptions } from '../../common/types/common-types';
import { idsAreEqual } from '../../common/utils';
import { assertFound, idsAreEqual } from '../../common/utils';
import { ConfigService } from '../../config/config.service';
import { TransactionalConnection } from '../../connection/transactional-connection';
import { OrderLine } from '../../entity/order-line/order-line.entity';
import { StockLevel } from '../../entity/stock-level/stock-level.entity';
import { StockLocation } from '../../entity/stock-location/stock-location.entity';
import { CustomFieldRelationService } from '../helpers/custom-field-relation/custom-field-relation.service';
import { ListQueryBuilder } from '../helpers/list-query-builder/list-query-builder';
import { RequestContextService } from '../helpers/request-context/request-context.service';
import { patchEntity } from '../helpers/utils/patch-entity';
Expand All @@ -43,6 +40,7 @@ export class StockLocationService {
private listQueryBuilder: ListQueryBuilder,
private configService: ConfigService,
private requestContextCache: RequestContextCacheService,
private customFieldRelationService: CustomFieldRelationService,
) {}

async initStockLocations() {
Expand Down Expand Up @@ -89,7 +87,14 @@ export class StockLocationService {
async update(ctx: RequestContext, input: UpdateStockLocationInput): Promise<StockLocation> {
const stockLocation = await this.connection.getEntityOrThrow(ctx, StockLocation, input.id);
const updatedStockLocation = patchEntity(stockLocation, input);
return this.connection.getRepository(ctx, StockLocation).save(updatedStockLocation);
await this.connection.getRepository(ctx, StockLocation).save(updatedStockLocation);
await this.customFieldRelationService.updateRelations(
ctx,
StockLocation,
input,
updatedStockLocation,
);
return assertFound(this.findOne(ctx, updatedStockLocation.id));
}

async delete(ctx: RequestContext, input: DeleteStockLocationInput): Promise<DeletionResponse> {
Expand Down
Loading