Skip to content

Commit

Permalink
fix(create): Update scaffolded service type safety for updated Enttity (
Browse files Browse the repository at this point in the history
#2712)

DeepPartial from typeorm and Vendure/core are different. This causes type issues on update.  Type safe way is to use patchEntity.
  • Loading branch information
arrrrny authored Mar 4, 2024
1 parent 767f833 commit 2e3be51
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TemplateContext } from '../../types';
export function renderService(context: TemplateContext) {
return /* language=TypeScript */ `
import { Inject, Injectable } from '@nestjs/common';
import { RequestContext, TransactionalConnection } from '@vendure/core';
import { RequestContext, TransactionalConnection, patchEntity } from '@vendure/core';
import { ${context.pluginInitOptionsName} } from '../constants';
import { PluginInitOptions } from '../types';
Expand Down Expand Up @@ -71,7 +71,7 @@ export class ${context.service.className} {
async update(ctx: RequestContext, input: Update${context.customEntityName}Input): Promise<${context.customEntityName}> {
const example = await this.connection.getEntityOrThrow(ctx, ${context.customEntityName}, input.id);
const updated = { ...example, ...input };
const updated = patchEntity(example, input);
return this.connection.getRepository(ctx, ${context.customEntityName}).save(updated);
}
}
Expand Down

0 comments on commit 2e3be51

Please sign in to comment.