Add simple user model
This commit is contained in:
35
api/src/functions/identity-signup.js
Normal file
35
api/src/functions/identity-signup.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import { createUser } from 'src/services/users/users.js'
|
||||
|
||||
export const handler = async (req, _context) => {
|
||||
const body = JSON.parse(req.body)
|
||||
console.log(body)
|
||||
console.log(_context)
|
||||
|
||||
const eventType = body.event
|
||||
const user = body.user
|
||||
const email = user.email
|
||||
|
||||
let roles = []
|
||||
|
||||
if (eventType === 'signup') {
|
||||
roles.push('user')
|
||||
const hi = {
|
||||
email: 'kurt.hutten@gmail.com',
|
||||
image: '',
|
||||
bio: ''
|
||||
}
|
||||
const input = {
|
||||
email,
|
||||
}
|
||||
createUser({input})
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify({ app_metadata: { roles: roles } }),
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
statusCode: 200,
|
||||
}
|
||||
}
|
||||
}
|
||||
35
api/src/graphql/users.sdl.js
Normal file
35
api/src/graphql/users.sdl.js
Normal file
@@ -0,0 +1,35 @@
|
||||
export const schema = gql`
|
||||
type User {
|
||||
id: Int!
|
||||
email: String!
|
||||
createdAt: DateTime!
|
||||
updatedAt: DateTime!
|
||||
image: String
|
||||
bio: String
|
||||
}
|
||||
|
||||
type Query {
|
||||
users: [User!]!
|
||||
user(id: Int!): User
|
||||
}
|
||||
|
||||
input CreateUserInput {
|
||||
email: String!
|
||||
issuer: String!
|
||||
image: String
|
||||
bio: String
|
||||
}
|
||||
|
||||
input UpdateUserInput {
|
||||
email: String
|
||||
issuer: String
|
||||
image: String
|
||||
bio: String
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
createUser(input: CreateUserInput!): User!
|
||||
updateUser(id: Int!, input: UpdateUserInput!): User!
|
||||
deleteUser(id: Int!): User!
|
||||
}
|
||||
`
|
||||
38
api/src/services/users/users.js
Normal file
38
api/src/services/users/users.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import { db } from 'src/lib/db'
|
||||
import { requireAuth } from 'src/lib/auth'
|
||||
|
||||
export const users = () => {
|
||||
requireAuth({ role: 'admin' })
|
||||
return db.user.findMany()
|
||||
}
|
||||
|
||||
export const user = ({ id }) => {
|
||||
requireAuth()
|
||||
return db.user.findOne({
|
||||
where: { id },
|
||||
})
|
||||
}
|
||||
|
||||
export const createUser = ({ input }) => {
|
||||
console.log(input)
|
||||
console.log(JSON.stringify(input))
|
||||
requireAuth({ role: 'admin' })
|
||||
return db.user.create({
|
||||
data: input,
|
||||
})
|
||||
}
|
||||
|
||||
export const updateUser = ({ id, input }) => {
|
||||
requireAuth()
|
||||
return db.user.update({
|
||||
data: input,
|
||||
where: { id },
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteUser = ({ id }) => {
|
||||
requireAuth({ role: 'admin' })
|
||||
return db.user.delete({
|
||||
where: { id },
|
||||
})
|
||||
}
|
||||
9
api/src/services/users/users.test.js
Normal file
9
api/src/services/users/users.test.js
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
import { users } from './users'
|
||||
*/
|
||||
|
||||
describe('users', () => {
|
||||
it('returns true', () => {
|
||||
expect(true).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user