Skip to content

Commit

Permalink
login, retrieve user and register user b00tc4mp#407
Browse files Browse the repository at this point in the history
  • Loading branch information
berlem authored and berlem committed Mar 17, 2024
1 parent a308169 commit 38d8c55
Show file tree
Hide file tree
Showing 64 changed files with 4,357 additions and 4 deletions.
5 changes: 4 additions & 1 deletion staff/belen-ivars/project/api/handlers/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import registerUserHandler from './registerUserHandler.js'
import authenticateUserHandler from './authenticateUserHandler.js'
import retrieveUserHandler from './retrieveUserHandler.js'


export {
registerUserHandler,
authenticateUserHandler
authenticateUserHandler,
retrieveUserHandler
}
29 changes: 29 additions & 0 deletions staff/belen-ivars/project/api/handlers/retrieveUserHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ContentError, NotFoundError } from 'com/errors.js'
import logic from '../logic/index.js'
import { validate } from 'com'

const complexRetrieve = async (req, res) => {
const userId = req.params.id

try {
validate.id(userId, 'id')
} catch (e) {
res.status(400).send()
return
}

try {
const user = await logic.retrieveUser(userId)
res.status(200).send(user)
} catch (e) {
if (e instanceof NotFoundError) {
res.status(404).send(e)
} else if (e instanceof ContentError) {
res.status(400).send(e)
} else {
res.status(500).send(e)
}
}
}

export default complexRetrieve
5 changes: 4 additions & 1 deletion staff/belen-ivars/project/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import cors from 'cors'

import {
registerUserHandler,
authenticateUserHandler
authenticateUserHandler,
retrieveUserHandler

} from './handlers/index.js'

Expand All @@ -25,6 +26,8 @@ mongoose.connect(process.env.MONGODB_URL)

server.post('/users/auth', jsonBodyParser, authenticateUserHandler)

server.get('/users/:id', jsonBodyParser, retrieveUserHandler)

server.listen(process.env.PORT, () => console.log(`server running on port ${process.env.PORT}`))
})

Expand Down
4 changes: 3 additions & 1 deletion staff/belen-ivars/project/api/logic/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import registerUser from './registerUser.js'
import authenticateUser from './authenticateUser.js'
import retrieveUser from './retrieveUser.js'

const logic = {
registerUser,
authenticateUser
authenticateUser,
retrieveUser
}

export default logic
17 changes: 17 additions & 0 deletions staff/belen-ivars/project/api/logic/retrieveUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NotFoundError } from "com/errors.js"
import { User } from "../data/models.js"

async function retrieveUser(id) {

const user = await User.findById(id)

console.log(user)

if (!user) {
console.log("no user found")
throw new NotFoundError("No user found :cry:")
}
return user
}

export default retrieveUser
21 changes: 21 additions & 0 deletions staff/belen-ivars/project/app/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
settings: { react: { version: '18.2' } },
plugins: ['react-refresh'],
rules: {
'react/jsx-no-target-blank': 'off',
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
24 changes: 24 additions & 0 deletions staff/belen-ivars/project/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
8 changes: 8 additions & 0 deletions staff/belen-ivars/project/app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
16 changes: 16 additions & 0 deletions staff/belen-ivars/project/app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png+xml" href="/borrello-berlem.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Basic Pantry 🥣</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>

</html>
32 changes: 32 additions & 0 deletions staff/belen-ivars/project/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "app",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"com": "link:../com",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-gravatar": "^2.6.3",
"react-router-dom": "^6.22.1"
},
"devDependencies": {
"@types/react": "^18.2.56",
"@types/react-dom": "^18.2.19",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.17",
"eslint": "^8.56.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"postcss": "^8.4.35",
"tailwindcss": "^3.4.1",
"vite": "^5.1.4"
}
}
Loading

0 comments on commit 38d8c55

Please sign in to comment.