Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/fullstack #21

Open
wants to merge 125 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
c01b176
feature/full stack branch created
jmarioav Jun 26, 2023
fc66546
second push
jmarioav Jun 26, 2023
03ab545
update down
jmarioav Jun 27, 2023
947a523
create add file
jmarioav Jun 27, 2023
1ed8e68
working cars 2
jmarioav Jun 27, 2023
1e345d7
update 18:08 on Jun 28th
jmarioav Jun 28, 2023
851d167
update 18:16 on Jun 28th
jmarioav Jun 28, 2023
9f8f960
storage with OOP
jmarioav Jun 28, 2023
d73d5e9
stuff update jun 29th
jmarioav Jun 29, 2023
19d2940
draft storage OOP
jmarioav Jun 29, 2023
78dd424
update app with OOP
jmarioav Jun 29, 2023
076ac69
refactoring app with OOP
jmarioav Jun 29, 2023
63aa5b8
refactoring app with OOP
jmarioav Jun 29, 2023
e16f3dd
app with several stores
jmarioav Jun 30, 2023
33ccd75
working first steps in mongo
jmarioav Jun 30, 2023
8418d75
working update 1 first steps in mongo
jmarioav Jun 30, 2023
dfb6596
api with aut-reg-ret de user
jmarioav Jul 1, 2023
0dec419
api logic with control error in test function
jmarioav Jul 3, 2023
c2c44b8
working api with IA auto-comments
jmarioav Jul 3, 2023
017233a
populate api
jmarioav Jul 3, 2023
c6c4f62
beta version of validator
jmarioav Jul 4, 2023
22a8711
update 1 beta version of validator
jmarioav Jul 4, 2023
a95b4aa
createPost finished
jmarioav Jul 4, 2023
b767f3f
retrievePosts and createPost finished
jmarioav Jul 4, 2023
b3b08ef
finish Post CRUD
jmarioav Jul 5, 2023
25fbee0
refactoring finish Post CRUD
jmarioav Jul 5, 2023
fdf80d4
api with retrievePosts
jmarioav Jul 6, 2023
7a640fd
api with retrievePosts
jmarioav Jul 6, 2023
5b1f47c
refactoring 1 api with retrievePosts
jmarioav Jul 6, 2023
6723aa5
refactoring 2 api with retrievePosts
jmarioav Jul 6, 2023
1ccc3c8
fully api done
jmarioav Jul 7, 2023
79639a4
refactoring fully api done
jmarioav Jul 9, 2023
db21b0e
refactoring fully api done
jmarioav Jul 10, 2023
8aa0a85
update 1 app-api merge
jmarioav Jul 10, 2023
fb2d771
update 2 app-api merge
jmarioav Jul 11, 2023
e839f71
update 2 app-api merge
jmarioav Jul 11, 2023
4f2f3b9
update 3 app-api merge
jmarioav Jul 12, 2023
9451d82
update 3 app-api merge
jmarioav Jul 12, 2023
8d83792
update 4 app-api merge
jmarioav Jul 12, 2023
140bee7
update 5 app-api merge
jmarioav Jul 12, 2023
633f206
update 6 app-api merge
jmarioav Jul 13, 2023
9dbf344
refactoring 1 app-api merge
jmarioav Jul 13, 2023
0a5274c
refactoring 2 app-api merge
jmarioav Jul 13, 2023
db27a5f
refactoring 3 app-api merge
jmarioav Jul 13, 2023
023fb9a
refactoring 4 app-api merge
jmarioav Jul 13, 2023
e6b33a8
refactoring 4 app-api merge
jmarioav Jul 13, 2023
04015be
refactoring home app-api merge
jmarioav Jul 15, 2023
2a4ca5f
workshop jul17th
jmarioav Jul 17, 2023
e0cf35f
fix css app
jmarioav Jul 18, 2023
b7df44f
do toggle favs api full logic
jmarioav Jul 19, 2023
177128b
refactoring toggle favs api full logic
jmarioav Jul 19, 2023
0860ff0
traslate app to vite
jmarioav Jul 20, 2023
742c1fd
favorite logic app-api
jmarioav Jul 20, 2023
ac0a059
mongoose update in api
jmarioav Jul 22, 2023
c19914b
mongoose update in app-api
jmarioav Jul 22, 2023
fa3dc91
update jul24th-1 quad project
jmarioav Jul 24, 2023
e55319f
update jul24th-2 quad project
jmarioav Jul 24, 2023
89d1d43
update jul25th-1 quad
jmarioav Jul 25, 2023
6ee678c
update jul26th-1 quad
jmarioav Jul 26, 2023
9e8b7e5
update jul27th-1 quad
jmarioav Jul 27, 2023
c5c67ea
update jul27th-2 quad
jmarioav Jul 27, 2023
39df233
update jul30th-1 quad
jmarioav Jul 30, 2023
747365e
update jul31th-1 quad
jmarioav Jul 31, 2023
72fb04d
update jul31th-1 quad
jmarioav Jul 31, 2023
294561f
update jul31th-2 quad
jmarioav Jul 31, 2023
ff73c48
update jul31th-3 quad
jmarioav Jul 31, 2023
6fd7a4d
update jul31th-3 quad
jmarioav Jul 31, 2023
a0b9ceb
update jul31th-4 quad/api data model change
jmarioav Jul 31, 2023
9a12511
update jul31th-4 quad/api data model change
jmarioav Jul 31, 2023
13647b3
update jul31th-4 quad/api data model change
jmarioav Jul 31, 2023
029bd84
update jul31th-4 quad/api data model change
jmarioav Jul 31, 2023
595c44a
update jul31th-5 quad
jmarioav Jul 31, 2023
e04303e
update jul31th-5 quad
jmarioav Jul 31, 2023
f67e5cd
update ago1st-1 quad
jmarioav Aug 1, 2023
da1fe56
update ago1st-2 quad
jmarioav Aug 1, 2023
85d44dd
update ago2st-1 quad
jmarioav Aug 2, 2023
44abbe6
update ago2st-2 quad: integrate canvas in app React
jmarioav Aug 2, 2023
cd1ab7b
refactor packages in quad project (rename files and folders)
jmarioav Aug 3, 2023
1803829
syntax fixes in quad project
jmarioav Aug 3, 2023
9ecde65
syntax fixes in quad project
jmarioav Aug 3, 2023
0330681
syntax fixes in quad project
jmarioav Aug 3, 2023
35a0e53
move mongoose and models to dat package; move utils to com package
jmarioav Aug 4, 2023
b46c3bd
refactoring optimize algorithm
jmarioav Aug 4, 2023
eb2ed1f
refectoring 1 opt
jmarioav Aug 4, 2023
3989973
version 1st quad project
jmarioav Aug 4, 2023
9c32ce1
refactoring 2 optimize algorithm
jmarioav Aug 5, 2023
292f507
clean duplicate insertion vertexs
jmarioav Aug 6, 2023
754e3a9
add vertex of medium segment for each block
jmarioav Aug 6, 2023
4335223
add vertex of medium segment for each block
jmarioav Aug 6, 2023
f548132
display id, nesting, and interations of process
jmarioav Aug 7, 2023
754e222
new re-edit button
jmarioav Aug 7, 2023
71702d7
fix css
jmarioav Aug 7, 2023
89f742d
do one process working; fix bugs of context
jmarioav Aug 8, 2023
108a3cb
fix style of optimize algorithm
jmarioav Aug 8, 2023
3d9d943
fix refresh interfece with modals
jmarioav Aug 9, 2023
9370649
fix com export to app
jmarioav Aug 9, 2023
8a3a1e5
refactoring home
jmarioav Aug 9, 2023
4a5d54d
fix rectangles draw
jmarioav Aug 9, 2023
ffe1be2
include medium point vertexs of panel edge
jmarioav Aug 10, 2023
0f29675
do optimization animation
jmarioav Aug 12, 2023
ffcdcb9
do optimization animation
jmarioav Aug 12, 2023
98193d6
comment quad code
jmarioav Aug 13, 2023
045d0db
sanitaze owner in api of quad
jmarioav Aug 14, 2023
8618bd5
add reset option to opt
jmarioav Aug 14, 2023
e3f2a21
add reset option to opt
jmarioav Aug 14, 2023
30504ab
adjust colors
jmarioav Aug 14, 2023
a017cd8
update readme
jmarioav Aug 15, 2023
7d8df65
figma fix
jmarioav Aug 16, 2023
5e9d0a8
refractoring readme
jmarioav Aug 16, 2023
c568973
labyrinth
jmarioav Aug 17, 2023
9cd61cb
do mocha-chai for users logic
jmarioav Aug 18, 2023
16f7030
no tailwind
jmarioav Aug 19, 2023
28fa45f
on progress mocha
jmarioav Aug 19, 2023
fff164d
mocha chai api fulfilled
jmarioav Aug 19, 2023
c722129
tailwin again
jmarioav Aug 21, 2023
84911cb
back to css
jmarioav Aug 21, 2023
b599087
clean old files
jmarioav Aug 22, 2023
d279495
tailwind reinstalled
jmarioav Aug 22, 2023
ff30a86
fulfill quad tailwind
jmarioav Aug 23, 2023
6243ff7
fix styles
jmarioav Aug 24, 2023
f233f18
optimization not possible warning
jmarioav Aug 25, 2023
8b25992
refactoring optimization panel
jmarioav Aug 26, 2023
42b2392
animate tailwind
jmarioav Aug 27, 2023
e8cb935
refactoring quad
jmarioav Sep 14, 2023
ef6d312
update logo
jmarioav Sep 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"docwriter.language": "English",
"docwriter.style": "JSDoc",
"docwriter.progress.trackClasses": true
}
84 changes: 84 additions & 0 deletions staff/mario-aller/fullstack/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# api

## Functional Description (FDS)

This process manage the connection of database to the user interface

## Technical Specs.

### Enviroment Variables (.env)

- API_PORT = port of API

- JWT_SECRET = secret string for jsonwebtoken

- MONGOOSE_URL = mongodb address

### Modules to be installed previosly
- cors
- dotenv
- express
- jsonwebtoken
- dat
```sh
npm install
```

### To execute the api

Place in api root directory ~/quad/api

- execute MongoDB

```sh
~/mongodb --dbpath data
```

- run
```sh
npm run start
```

### Test Coverage

File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------------------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
panels | 100 | 100 | 100 | 100 |
createBlock.js | 100 | 100 | 100 | 100 |
createBlock.spec.js | 100 | 100 | 100 | 100 |
createPanel.js | 100 | 100 | 100 | 100 |
createPanel.spec.js | 100 | 100 | 100 | 100 |
deleteBlock.js | 100 | 100 | 100 | 100 |
deleteBlock.spec.js | 100 | 100 | 100 | 100 |
deletePanel.js | 100 | 100 | 100 | 100 |
deletePanel.spec.js | 100 | 100 | 100 | 100 |
index.js | 100 | 100 | 100 | 100 |
retrievePanelOne.js | 100 | 100 | 100 | 100 |
retrievePanelOne.spec.js | 100 | 100 | 100 | 100 |
retrievePanelWorking.js | 100 | 100 | 100 | 100 |
retrievePanelWorking.spec.js | 100 | 100 | 100 | 100 |
retrievePanels.js | 100 | 100 | 100 | 100 |
retrievePanels.spec.js | 100 | 100 | 100 | 100 |
updatePanel.js | 100 | 100 | 100 | 100 |
updatePanel.spec.js | 100 | 100 | 100 | 100 |
updatePanelStatusReEdit.js | 100 | 100 | 100 | 100 |
updatePanelStatusReEdit.spec.js | 100 | 100 | 100 | 100 |
updatePanelStatusToOptimize.js | 100 | 100 | 100 | 100 |
updatePanelStatusToOptimize.spec.js | 100 | 100 | 100 | 100 |
users | 100 | 100 | 100 | 100 |
authenticateUser.js | 100 | 100 | 100 | 100 |
authenticateUser.spec.js | 100 | 100 | 100 | 100 |
index.js | 100 | 100 | 100 | 100 |
registerUser.js | 100 | 100 | 100 | 100 |
registerUser.spec.js | 100 | 100 | 100 | 100 |
retrieveUser.js | 100 | 100 | 100 | 100 |
retrieveUser.spec.js | 100 | 100 | 100 | 100 |
updateUser.js | 100 | 100 | 100 | 100 |
updateUser.spec.js | 100 | 100 | 100 | 100 |

Lines
- panels 630/630
- users 153/153

[Home](../doc/README.md)
263 changes: 263 additions & 0 deletions staff/mario-aller/fullstack/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
// Enviroment
require('dotenv').config()
const {
API_PORT,
JWT_SECRET,
MONGOOSE_URL
} = process.env

// Modules
const { mongoose } = require('dat')
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const jwt = require('jsonwebtoken')

// User-defined modules
// const { Dimension, Dimension2D, Block, Panel } = require('./logic/classes')
// const { sleep, display, validateString } = require('./logic/helpers')

const {
registerUser,
authenticateUser,
retrieveUser,
updateUser
} = require('./logic/users')

const {
createPanel,
retrievePanels,
retrievePanelOne,
retrievePanelWorking,
updatePanel,
updatePanelStatusToOptimize,
updatePanelStatusReEdit,
deletePanel,
createBlock,
deleteBlock
} = require('./logic/panels')

const api = express()
const jsonBodyParser = bodyParser.json()

mongoose.connect(MONGOOSE_URL)
.then(() => {
api.use(cors())

// registerUser
/* This code is defining a route for the HTTP POST method at the '/users' endpoint. When a POST
request is made to this endpoint, the code inside the callback function will be executed. */
api.post('/users', jsonBodyParser, (req, res) => {
try {
const { name, surname, zip, email, password } = req.body

registerUser(name, surname, zip, email, password)
.then(() => res.status(201).send())
.catch(error => res.status(400).json({ error: error.message }))
} catch (error) { res.status(400).json({ error: error.message }) }
})

// authenticateUser
/* This code defines a route for the HTTP POST method at the '/users/auth' endpoint. When a
POST request is made to this endpoint, the code inside the callback function will be
executed. */
api.post('/users/auth', jsonBodyParser, (req, res) => {
try {
const { email, password } = req.body

authenticateUser(email, password)
.then((userId) => {
const token = jwt.sign({ sub: userId }, JWT_SECRET)
res.json(token)
})
.catch(error => res.status(400).json({ error: error.message }))
} catch (error) { res.status(400).json({ error: error.message }) }
})

// retrieveUser
/* This code defines a route for the HTTP GET method at the '/users' endpoint. When a GET request is
made to this endpoint, the code inside the callback function will be executed. */
api.get('/users', (req, res) => {
try {
const token = req.headers.authorization.slice(7)
const userId = jwt.verify(token, JWT_SECRET).sub
retrieveUser(userId)
.then(user => res.json(user))
.catch(error => res.status(400).json({ error: error.message }))
} catch (error) { res.status(400).json({ error: error.message }) }
})

// updateUser
/* This code is defining a route for the HTTP PATCH method at the '/users' endpoint. When a PATCH
request is made to this endpoint, the code inside the callback function will be executed. */
api.patch('/users', jsonBodyParser, (req, res) => {
try {
const token = req.headers.authorization.slice(7)
const userId = jwt.verify(token, JWT_SECRET).sub

const { name, surname, zip } = req.body

updateUser(userId, name, surname, zip)
.then(() => res.send())
.catch(error => res.status(400).json({ error: error.message }))
} catch (error) { res.status(400).json({ error: error.message }) }
})

// createPanel
/* This code is defining a route for the HTTP POST method at the '/panels' endpoint. When a POST
request is made to this endpoint, the code inside the callback function will be executed. */
api.post('/panels', jsonBodyParser, (req, res) => {
try {
const token = req.headers.authorization.slice(7)
const userId = jwt.verify(token, JWT_SECRET).sub

const { reference, width, height } = req.body

createPanel(userId, reference, width, height)
.then(() => res.status(201).send())
.catch(error => res.status(400).json({ error: error.message }))
} catch (error) { res.status(400).json({ error: error.message }) }
})

// retrievePanels
/* This code is defining a route for the HTTP GET method at the '/panels' endpoint. When a GET request
is made to this endpoint, the code inside the callback function will be executed. */
api.get('/panels', (req, res) => {
try {
const token = req.headers.authorization.slice(7)
const userId = jwt.verify(token, JWT_SECRET).sub
retrievePanels(userId)
.then(panels => res.json(panels))
.catch(error => res.status(400).json({ error: error.message }))
} catch (error) { res.status(400).json({ error: error.message }) }
})

// retrievePanelOne
/* This code is defining a route for the HTTP GET method at the '/panels/:panelId' endpoint. When a GET
request is made to this endpoint, the code inside the callback function will be executed. */
api.get('/panels/:panelId', (req, res) => {
try {
const token = req.headers.authorization.slice(7)
const userId = jwt.verify(token, JWT_SECRET).sub
const { panelId } = req.params

retrievePanelOne(userId, panelId)
.then(panel => res.json(panel))
.catch(error => res.status(400).json({ error: error.message }))
} catch (error) { res.status(400).json({ error: error.message }) }
})

// retrievePanelWorking
/* This code defines a route for the HTTP GET method at the '/panels/:panelId/work' endpoint. When a
GET request is made to this endpoint, the code inside the callback function will be executed. */
api.get('/panels/:panelId/work', (req, res) => {
try {
const token = req.headers.authorization.slice(7)
const userId = jwt.verify(token, JWT_SECRET).sub
const { panelId } = req.params

retrievePanelWorking(userId, panelId)
.then(coors => res.json(coors))
.catch(error => res.status(400).json({ error: error.message }))
} catch (error) { res.status(400).json({ error: error.message }) }
})

// updatePanel
/* The code you provided is defining a route for the HTTP PATCH method at the '/panels/:panelId'
endpoint. When a PATCH request is made to this endpoint, the code inside the callback function will
be executed. */
api.patch('/panels/:panelId', jsonBodyParser, (req, res) => {
try {
const token = req.headers.authorization.slice(7)
const userId = jwt.verify(token, JWT_SECRET).sub
const { panelId } = req.params

const { reference, width, height } = req.body

updatePanel(userId, panelId, reference, width, height)
.then(() => res.send())
.catch(error => res.status(400).json({ error: error.message }))
} catch (error) { res.status(400).json({ error: error.message }) }
})

// updatePanelStatusToOptimize
/* This code is defining a route for the HTTP PATCH method at the '/panels/:panelId/optimize' endpoint.
When a PATCH request is made to this endpoint, the code inside the callback function will be
executed. */
api.patch('/panels/:panelId/optimize', (req, res) => {
try {
const token = req.headers.authorization.slice(7)
const userId = jwt.verify(token, JWT_SECRET).sub
const { panelId } = req.params

return updatePanelStatusToOptimize(userId, panelId)
.then(() => res.send())
.catch(error => res.status(400).json({ error: error.message }))
} catch (error) { res.status(400).json({ error: error.message }) }
})

// updatePanelStatusReEdit
/* This code defines a route for the HTTP PATCH method at the '/panels/status/reedit/:panelId'
endpoint. When a PATCH request is made to this endpoint, the code inside the callback function will
be executed. */
api.patch('/panels/status/reedit/:panelId', (req, res) => {
try {
const token = req.headers.authorization.slice(7)
const userId = jwt.verify(token, JWT_SECRET).sub
const { panelId } = req.params

updatePanelStatusReEdit(userId, panelId)
.then(() => res.send())
.catch(error => res.status(400).json({ error: error.message }))
} catch (error) { res.status(400).json({ error: error.message }) }
})

// deletePanel
/* This code is defining a route for the HTTP DELETE method at the '/panels/:panelId' endpoint. When a
DELETE request is made to this endpoint, the code inside the callback function will be executed. */
api.delete('/panels/:panelId', jsonBodyParser, (req, res) => {
try {
const token = req.headers.authorization.slice(7)
const userId = jwt.verify(token, JWT_SECRET).sub
const { panelId } = req.params

deletePanel(userId, panelId)
.then(() => res.send())
.catch(error => res.status(400).json({ error: error.message }))
} catch (error) { res.status(400).json({ error: error.message }) }
})

// createBlock
/* This code is defining a route for the HTTP POST method at the '/blocks' endpoint. When a POST
request is made to this endpoint, the code inside the callback function will be executed. */
api.post('/blocks', jsonBodyParser, (req, res) => {
try {
const token = req.headers.authorization.slice(7)
const userId = jwt.verify(token, JWT_SECRET).sub

const { panelId, width, height } = req.body

createBlock(userId, panelId, width, height)
.then(() => res.status(201).send())
.catch(error => res.status(400).json({ error: error.message }))
} catch (error) { res.status(400).json({ error: error.message }) }
})

// deleteBlock
/* The above code is defining a route handler for a DELETE request to '/blocks/:panelId/:blockId'. It
first extracts the token from the 'Authorization' header and verifies it using a JWT secret. Then,
it extracts the 'panelId' and 'blockId' parameters from the request URL. */
api.delete('/blocks/:panelId/:blockId', jsonBodyParser, (req, res) => {
try {
const token = req.headers.authorization.slice(7)
const userId = jwt.verify(token, JWT_SECRET).sub
const { panelId, blockId } = req.params

deleteBlock(userId, panelId, blockId)
.then(() => res.send())
.catch(error => res.status(400).json({ error: error.message }))
} catch (error) { res.status(400).json({ error: error.message }) }
})

api.listen(API_PORT, () => console.log(`API working in port ${API_PORT} ...`))
})
32 changes: 32 additions & 0 deletions staff/mario-aller/fullstack/api/logic/panels/createBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { models: { UserModel, PanelModel } } = require('dat')
const { validateString } = require('com')

/**
* The function creates a block with the specified width and height in a panel associated with a user.
* @param userId - The `userId` parameter is the unique identifier of the user for whom the block is
* being created.
* @param panelId - The `panelId` parameter is the unique identifier of the panel where the block will
* be created.
* @param width - The width of the block to be created.
* @param height - The height parameter represents the height of the block that will be created.
* @returns a Promise.
*/
function createBlock(userId, panelId, width, height) {
return Promise.all([UserModel.findById(userId, '_id').lean(), PanelModel.findById(panelId)])
.then(([user, panel]) => {
if (!user) throw new Error('user does not exist')
if (!panel) throw new Error('panel does not exist')

const x = -1
const y = -1
const orientation = 0
const block = { x, y, width: Number(width), height: Number(height), orientation }
panel.blocks.push(block)
panel.status = 0
return panel.save()
})
.then(() => { })

}

module.exports = createBlock
Loading