DB Model Design For Invite System

Solution for DB Model Design For Invite System
is Given Below:

In my app, I have an invite system. Conditions being:

  • User create a board, there can only be one active board at a time
  • User can send invites to other board-creators
  • For boards to be shown to user in search results, they must have min. of 2 entries
  • Once a board has been sent an invite, or if an invite from other board-creator has been ignored, they must not appear in search results again while the current board is active.

The Db models I have created:

model GoalBoard {
  id             String       @id @default(cuid())
  isActive       Boolean      @default(true)
  createdAt      DateTime     @default(now())
  expiresAt      DateTime?
  goal           Goal[]
  goalOwner      User         @relation(fields: [goalOwnerId], references: [id])
  goalOwnerId    String
  inviteSent     Invite[]     @relation("inviteFromGB")
  inviteReceived Invite[]     @relation("inviteToGB")
  ...
}

model Invite {
  id           String    @id @default(cuid())
  fromGB       GoalBoard @relation("inviteFromGB", fields: [fromGBId], references: [id])
  fromGBId     String
  toGB         GoalBoard @relation("inviteToGB", fields: [toGBId], references: [id])
  toGBId       String
  isAccepted   Boolean   @default(false)
  isValid      Boolean   @default(true) // is still relevant or expired?
  dateSent     DateTime  @default(now())
  dateAccepted DateTime?
}

The definition format is in Prisma.js, however that is relevant and the question is about how to design the models. I am not sure this is an ideal structure as I am struggling to implement the checks into the query.

My question is, how can I make this structure easier to query and implement and update with queries/ mutations.

Thanks