Fergus Meiklejohn
02/07/2022, 3:36 AMexport function removeNull(obj: any): any {
if (!obj) return obj;
if (obj instanceof Date) return obj;
else {
return Object.fromEntries(
Object.entries(obj)
.filter(([_, v]) => v != null)
.map(([k, v]) => [k, v === Object(v) ? removeNull(v) : v])
);
}
}
And before I added the instanceof check it was removing all Date types from the response because JS types Date as an object 🤪
The result was returning objects with {insertedAt: {} ... }
Maybe I'm missing a native Prisma method to remove nulls from queries??