From 4542c56a8743f4adb2c752f814062a9a78d97785 Mon Sep 17 00:00:00 2001 From: Ahmet TOK <48218623+arrrrny@users.noreply.github.com> Date: Sat, 2 Mar 2024 02:38:08 +0300 Subject: [PATCH] Update service.ts Type safet for updated Enttity DeepPartial from typeorm and Vendure/core are different. This causes type issues on update. Type safe way is to use patchEntity. --- .../cli/src/commands/new/plugin/scaffold/services/service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/new/plugin/scaffold/services/service.ts b/packages/cli/src/commands/new/plugin/scaffold/services/service.ts index 54e7f25e37..f31e39e916 100644 --- a/packages/cli/src/commands/new/plugin/scaffold/services/service.ts +++ b/packages/cli/src/commands/new/plugin/scaffold/services/service.ts @@ -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'; @@ -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); } }