diff --git a/lib/relationships/pick.ts b/lib/relationships/pick.ts index 0e9ff2e..a54f476 100644 --- a/lib/relationships/pick.ts +++ b/lib/relationships/pick.ts @@ -3,6 +3,7 @@ import sift from "sift"; import { SeedRelationPicker, SeederContext } from "../interfaces"; import { Logger } from "@nestjs/common"; import { inspect } from "util"; +import * as util from "util"; const logger = new Logger("SeedRelation"); @@ -44,11 +45,18 @@ export async function pickRelated( } else { ((_: never) => {})(pick); } - return restrict(idColumns, picked); + try { + return restrict(idColumns, picked); + } catch (e) { + throw new Error( + `Picked invalid relationship object(s): ${util.inspect(picked)}` + ); + } } function restrict(cols: string[], pick: T | T[]): any { if (Array.isArray(pick)) return pick.map((v) => restrict(cols, v)); + else if (pick === null || pick === undefined) return null; return Object.fromEntries( Object.entries(pick).filter((kv) => cols.includes(kv[0])) ); diff --git a/package.json b/package.json index 2085e82..c5fabe2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nestjs-class-seeder", - "version": "1.1.3", + "version": "1.1.4", "description": "An extension library for NestJS to perform seeding. Forked from nestjs-seeder", "main": "dist/index.js", "types": "dist/index.d.ts",