add contact page

This commit is contained in:
Kurt Hutten
2020-10-12 19:19:27 +11:00
parent b3456860d2
commit 6a95795760
15 changed files with 363 additions and 2 deletions

View File

@@ -0,0 +1,24 @@
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 create new contact", {
messages: {
email: ['is not formatted like an email address'],
},
})
}
}
export const contacts = () => {
return db.contact.findMany()
}
export const createContact = ({ input }) => {
validate(input)
return db.contact.create({ data: input })
}