text: import { UserInputError } from '@redwoodjs/api'
  
  import { db } from 'src/lib/db'
  
  const validate = (input) => {
    if (input.email && !input.email.match(/[^@]+@[^.]+\..+/)) {
      throw new UserInputError("Can't submit", {
        messages: { email: ['is not formatted like an email address'] },
      })
    }
  }
  
  export const users = () => {
    return db.user.findMany()
  }
  
  export const user = ({ id }) => {
    return db.user.findOne({
      where: { id },
    })
  }
  
  export const createUser = ({ input }) => {
    validate(input)
    return db.user.create({
      data: input,
    })
  }
  
  export const updateUser = ({ id, input }) => {
    return db.user.update({
      data: input,
      where: { id },
    })
  }
  
  export const deleteUser = ({ id }) => {
    return db.user.delete({
      where: { id },
    })
  }
  