【问题标题】:Conditional query Prisma assigning a value using date条件查询 Prisma 使用日期赋值
【发布时间】:2022-12-02 20:19:51
【问题描述】:

I want to find the menus type provided by the restaurant (breakfast type) according to the time now, and the hours to display is on ShowingHours model

I created a Menu model

model Menu {
  id             String         @id @default(cuid())
  type           String?
  branchId       String
  branch         Branch         @relation(fields: [branchId], references: [id])
  menuCategories MenuCategory[]

  ShowingHours   ShowingHours? @relation(fields: [showingHoursId], references: [id])
  showingHoursId String?
}

and ShowingHours

model ShowingHours {
  id         String  @id @default(cuid())
  fromHour   Int?
  fromMinute Int?
  toHour     Int?
  toMinute   Int?
  allDay     Boolean
  menus      Menu[]
}
    let timeNow = new Date().getHours();

I want to make a condition that if the value of timeNow for example is 9 am, then query a menu that has a inbetween timenow hours from \"fromHour\" to \"toHour\"

My approach:

let menuType = await db.menu.findMany({
      // between fromhour tohour
     where: {
      branchId: branchId,
//I WOULD LIKE TO MAKE A CONDITION LIKE: if timeNow >= fromHour && timenow < toHour then fetch 
      ShowingHours: {
        OR: [
          {
            fromHour: {
              in: 
            }
          }
        ]
      }
      },
     
      
    })

    标签: prisma


    【解决方案1】:
    猜你喜欢
    • 2022-08-21
    • 2020-12-18
    • 2021-03-06
    • 2020-10-19
    • 1970-01-01
    • 1970-01-01
    • 2020-11-10
    • 2014-08-24
    • 1970-01-01
    相关资源
    最近更新 更多