From 3d02d7973bec43e75c6c6cb45cf997d33f748332 Mon Sep 17 00:00:00 2001 From: XiaoZhang Date: Sat, 24 Jul 2021 09:27:40 +0800 Subject: [PATCH] fix(query-typegoose): ignore undefined id field in creation dto (#1165) --- .../query-typegoose/src/services/typegoose-query-service.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/query-typegoose/src/services/typegoose-query-service.ts b/packages/query-typegoose/src/services/typegoose-query-service.ts index 759bc348a..36e375781 100644 --- a/packages/query-typegoose/src/services/typegoose-query-service.ts +++ b/packages/query-typegoose/src/services/typegoose-query-service.ts @@ -237,7 +237,11 @@ export class TypegooseQueryService } private ensureIdIsNotPresent(e: DeepPartial): void { - if (Object.keys(e).find((f) => f === 'id' || f === '_id')) { + if ( + Object.keys(e) + .filter((v) => typeof e[v] !== `undefined`) + .find((f) => f === 'id' || f === '_id') + ) { throw new Error('Id cannot be specified when updating or creating'); } }