Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Auto configuration, based on field #6

Open
Ottavio97 opened this issue May 23, 2023 · 1 comment
Open

[Suggestion] Auto configuration, based on field #6

Ottavio97 opened this issue May 23, 2023 · 1 comment

Comments

@Ottavio97
Copy link

Ottavio97 commented May 23, 2023

Hi Olivier,
first of all, thanks for your middleware.

It would be a cool feature to autoconfigure models with soft-delete, wherever they contain the field configured in your middleware.

Imagine if you can put a new config parameter like autoConfigure: true, with this implementation I made for my project:

this.$use(
      createSoftDeleteMiddleware({
        models: Prisma.dmmf.datamodel.models
          .filter((m) => m.fields.some((f) => f.name == 'deletedAt'))
          .map((md) => ({ [md.name]: true }))
          .reduce((prev, next) => ({ ...prev, ...next }), {}),
        defaultConfig: {
          field: 'deletedAt',
          createValue: (deleted) => {
            if (deleted) return new Date();
            return null;
          },
        },
      }),

It may be really useful and more automatic.
Thanks again :)

@olivierwilkinson
Copy link
Owner

olivierwilkinson commented May 25, 2023

Hi there,

I'm glad you are finding the middleware helpful 🎉

That's an interesting idea, I can see this being a useful option! There are some other issues I need to look into first but I'll get round to this as soon as I have the bandwidth 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants