Skip to content

Commit

Permalink
feat: Add where in options (#487)
Browse files Browse the repository at this point in the history
* Add where in options

* Add changeset

* Comment options and turn into patch

---------

Co-authored-by: Colin Regourd <cregourd@premieroctet.com>
  • Loading branch information
didrikmunther and cregourd authored Nov 18, 2024
1 parent 3bffee1 commit 46a3dba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/blue-carrots-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": patch
---

Add where clause to model options
5 changes: 5 additions & 0 deletions apps/example/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export const options: NextAdminOptions = {
],
search: ["name", "email", "role"],
copy: ["email"],
// where: [{
// role: {
// equals: "USER",
// },
// }],
filters: [
{
name: "is Admin",
Expand Down
4 changes: 4 additions & 0 deletions packages/next-admin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@ export type ListOptions<T extends ModelName> = {
* define a set of Prisma filters that user can choose in list
*/
filters?: FilterWrapper<T>[];
/**
* define a set of Prisma filters that are always active in list
*/
where?: Filter<T>[];
};

export type SubmitResourceResponse =
Expand Down
5 changes: 4 additions & 1 deletion packages/next-admin/src/utils/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ const preparePrismaListRequest = <M extends ModelName>(
resource,
options,
search,
otherFilters: fieldFilters,
otherFilters: [
...fieldFilters ?? [],
...list?.where ?? []
],
advancedSearch,
});

Expand Down

0 comments on commit 46a3dba

Please sign in to comment.