Skip to content

Commit

Permalink
v1.1.4 allow pick null
Browse files Browse the repository at this point in the history
  • Loading branch information
Helveg committed Oct 26, 2023
1 parent 9395e21 commit 36acedf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/relationships/pick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -44,11 +45,18 @@ export async function pickRelated<T>(
} 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<T>(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]))
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 36acedf

Please sign in to comment.