add contact page
This commit is contained in:
24
api/src/services/contacts/contacts.js
Normal file
24
api/src/services/contacts/contacts.js
Normal 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 })
|
||||
}
|
||||
9
api/src/services/contacts/contacts.test.js
Normal file
9
api/src/services/contacts/contacts.test.js
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
import { contacts } from './contacts'
|
||||
*/
|
||||
|
||||
describe('contacts', () => {
|
||||
it('returns true', () => {
|
||||
expect(true).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user