添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hi, I need update a post which connect to a user.
When someone request to update a field in that post, what is the best way to check that is user is the post's owner?

update(user: JWT, postId: number, updatePostDto: UpdatePostDto) {
    return this.prm.deal.update({
      where: { id:postID, authorId: user.id }, // I have user ID here
      data: updateDealDto,
    });

I don't really want use updateMany. It doesn't return updated post.

Hey @IRediTOTO 👋 ,

The easiest way to do this is to update the post through the user.

let result = await prisma.user.update({
  where: { id: userId },
  data: {
    posts: {
      update: {
        where: { id: postId },
        data: { postDTO }

Let me know if that will work for you!

Hey @IRediTOTO 👋 ,

The easiest way to do this is to update the post through the user.

let result = await prisma.user.update({
  where: { id: userId },
  data: {
    posts: {
      update: {
        where: { id: postId },
        data: { postDTO }

Let me know if that will work for you!