Browse Source

fix(create): Update scaffolded service type safety for updated Enttity (#2712)

DeepPartial from typeorm and Vendure/core are different. This causes type issues on update.  Type safe way is to use patchEntity.
Ahmet TOK 1 year ago
parent
commit
2e3be5196d
1 changed files with 2 additions and 2 deletions
  1. 2 2
      packages/cli/src/commands/new/plugin/scaffold/services/service.ts

+ 2 - 2
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);
     }
 }