Skip to content

Commit

Permalink
fix: Update Relations on Stock Location update
Browse files Browse the repository at this point in the history
The Stock Location update method was not updating relation customFields

Refs: #2804
  • Loading branch information
dylviz committed Apr 22, 2024
1 parent c7a28b7 commit 98e6481
Showing 1 changed file with 12 additions and 7 deletions.
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

0 comments on commit 98e6481

Please sign in to comment.