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

How to handle createdAt and updatedAt with crud globally? #1009

Open
Newbie012 opened this issue Dec 28, 2020 · 0 comments
Open

How to handle createdAt and updatedAt with crud globally? #1009

Newbie012 opened this issue Dec 28, 2020 · 0 comments

Comments

@Newbie012
Copy link

First thing I came up with, is by calling computedInputs in the nexusPrisma option. But it won't work since they need to be handled differently depending on the situation, but globally:

1. create -> createdAt = now, updatedAt = null
2. update -> createdAt = keep as it is, updatedAt = now

In order to make it work, I need to set computedInputs individually like so:

t.crud.createOneX({
  computedInputs: {
    createdAt: () => DateTime.utc().toString(),
    updatedAt: () => null,
  },
});

t.crud.updateOneX({
  computedInputs: {
    createdAt: () => undefined,
    updatedAt: () => DateTime.utc().toString(),
  },
});

While this might work, I'm unable to "compute" these inputs on the nested models. In order to prevent passing createdAt/updatedAt, I have to create another t.crud on that resource as well, without these timestamps.

The last workaround for this that might work, is to not use t.crud at all, which is a bummer.

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

1 participant