Skip to content

Commit

Permalink
add role value to new user b00tc4mp#485
Browse files Browse the repository at this point in the history
  • Loading branch information
juditta99 committed Jun 17, 2024
1 parent 589bcf5 commit 9c68718
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
17 changes: 12 additions & 5 deletions staff/judy-grayland/project/api/logic/registerUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ function registerUser(name, email, password) {
throw new SystemError(error.message)
})
.then((hash) => {
return User.create({ name, email, password: hash })
return User.find()
.catch((error) => {
if (error.code === 11000) {
throw new DuplicityError('user already exists')
}
throw new SystemError(error.message)
})
.then((user) => {})
.then((users) => {
const role = users.length === 0 ? 'admin' : 'user'
return User.create({ name, email, password: hash, role })
.catch((error) => {
if (error.code === 11000) {
throw new DuplicityError('user already exists')
}
throw new SystemError(error.message)
})
.then((user) => {})
})
})
}

Expand Down
4 changes: 2 additions & 2 deletions staff/judy-grayland/project/app/src/pages/EditResource.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function EditResource() {
const [resourceType, setResourceType] = useState('activity')
const navigate = useNavigate()

function handleCreateResourceSuccess() {
function handleEditResourceSuccess() {
navigate('/resources')
}

Expand Down Expand Up @@ -70,7 +70,7 @@ function EditResource() {
logic
.createResource(data)
.then(() => {
handleCreateResourceSuccess()
handleEditResourceSuccess()
})
.catch((error) => {
console.error(error)
Expand Down
4 changes: 2 additions & 2 deletions staff/judy-grayland/project/app/src/pages/ResourcesList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function ResourcesList() {
navigate('/resources/new')
}

const displayResources = () => {
const fetchResources = () => {
try {
logic
.retrieveResources()
Expand All @@ -29,7 +29,7 @@ function ResourcesList() {
}
}
useEffect(() => {
displayResources()
fetchResources()
}, [])

return (
Expand Down

0 comments on commit 9c68718

Please sign in to comment.