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

Setting multiple fields on delete - deletedAt and deletedById #16

Open
rsslldnphy opened this issue Feb 7, 2024 · 0 comments
Open

Setting multiple fields on delete - deletedAt and deletedById #16

rsslldnphy opened this issue Feb 7, 2024 · 0 comments

Comments

@rsslldnphy
Copy link

rsslldnphy commented Feb 7, 2024

In our app we set a timestamp + userId pair when an entity is created, updated, or deleted - so for deletions, deletedAt and deletedById (a foreign key of the user table).

It would be great if createValue would allow us to set multiple fields when a record is deleted so both these could be set. Or alternatively, to keep the API backwards compatible, a createValues plural option could be added so the behaviour of the original option doesn't need to change.

I'd imagine it being used something like this:

const softdeletes = (user: User) => createSoftDeleteExtension({
    models: {
        User: true,
        Post: true,
    }
    defaultConfig: {
        field: "deletedAt",
        createValues: (deleted) => (
            deleted ? { deletedAt: new Date(), deletedById: user.id } : { }
        )
    }
})

export const getConnectionForUser = (user: User) => {
    return prisma.$extend(sofdeletes(user))
}

If this is of interest, I'd be happy having a crack at a PR?

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