Skip to content

Commit

Permalink
Merge pull request #217 from Arquisoft/master-dev
Browse files Browse the repository at this point in the history
Mejoras finales
  • Loading branch information
UO276208 authored May 2, 2022
2 parents 79a6d84 + 1855a0b commit 6344515
Show file tree
Hide file tree
Showing 66 changed files with 2,721 additions and 2,415 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/asw2122.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: 16
- run: touch .env
- run: echo "${{ secrets.ENV }}" > .env
- run: cp .env ./tests/.env
- run: npm ci
- run: npm test
- uses: codecov/codecov-action@v2
Expand Down Expand Up @@ -60,6 +63,10 @@ jobs:
workdir: webapp
docker-push-restapi:
name: Push restapi Docker Image to GitHub Packages
env:
MONGO_DB_URI: ${{ secrets.MONGO_DB_URI }}
SECRET_SALT: ${{ secrets.SECRET_SALT }}
SECRET: ${{ secrets.SECRET }}
runs-on: ubuntu-latest
needs: [unit-test-webapp, unit-test-restapi]
# needs: [e2e-tests]
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/develop-branch-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI Develop Branch

on:
push:
branches:
- 'dev'

jobs:
unit-test-webapp:
runs-on: ubuntu-latest
defaults:
run:
working-directory: webapp
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- run: npm ci
- run: npm test
- uses: codecov/codecov-action@v2
unit-test-restapi:
runs-on: ubuntu-latest
defaults:
run:
working-directory: restapi
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- run: touch .env
- run: echo "${{ secrets.ENV }}" > .env
- run: cp .env ./tests/.env
- run: npm ci
- run: npm test
- uses: codecov/codecov-action@v2
# e2e-tests:
# needs: [unit-test-webapp, unit-test-restapi]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - uses: actions/setup-node@v2
# with:
# node-version: 16
# - run: npm --prefix webapp install
# - run: npm --prefix restapi install
# - run: npm --prefix webapp run build
# - run: npm --prefix webapp run test:e2e
46 changes: 24 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
"dependencies": {
"@chec/commerce.js": "^2.8.0",
"@inrupt/solid-ui-react": "^2.7.0",
"@stripe/react-stripe-js": "^1.7.0",
"@stripe/stripe-js": "^1.26.0",
"react-hook-form": "^7.29.0",
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@stripe/react-stripe-js": "^1.7.2",
"@stripe/stripe-js": "^1.29.0",
"react-hook-form": "^7.30.0",
"react-router-dom": "^6.3.0"
}
}
5 changes: 5 additions & 0 deletions restapi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ COPY . /app
WORKDIR /app
#Install the dependencies
RUN npm install

ENV MONGO_DB_URI=$MONGO_DB_URI
ENV SECRET_SALT=$SECRET_SALT
ENV SECRET=$SECRET

CMD [ "npm", "start" ]
22 changes: 11 additions & 11 deletions restapi/controladores/LoginController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ const User = require('../models/user')
//funciones
const login = async (req: Request, res: Response) => {

const user = await User.findOne({'userName': req.body.userName})

const userName = req.body.userName

const user = await User.findOne({'userName': userName})

if(!user){

res.status(401).json({ error: "invalid user or password" })

} else {

const samePassword = await bcrypt.compare(req.body.password, user.password)

if(!samePassword){
res.status(401).json({ error: "invalid user or password" })
} else {
Expand All @@ -26,12 +28,12 @@ const login = async (req: Request, res: Response) => {
userName: req.body.userName,
role: user.role
}

const tokenSecret = process.env.SECRET

const token = jwt.sign(userToken, tokenSecret)
res.send({

res.status(200).json({
userName: user.userName,
name: user.Name,
token
Expand All @@ -41,10 +43,8 @@ const login = async (req: Request, res: Response) => {

}



}

module.exports = {
login,
login
}
84 changes: 84 additions & 0 deletions restapi/controladores/OrderController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Request, Response } from 'express';
const Order = require('../models/order')

//funciones
const findAllOrders = async (req: Request, res: Response) => {

//llamada al repositorio
const orders = await Order.find()

return res.status(200).send(orders);

}

const findOrder = async (req: Request, res: Response) => {

const order = await Order.findById(req.params.id)

return res.status(200).send(order);

}

const findOrderByClient = async (req: Request, res: Response) => {

const order = await Order.find({user: req.params.userName})

return res.status(200).send(order);

}

const deleteOrder = async (req: Request, res: Response) => {

//llamada al respositorio
await Order.findByIdAndDelete(req.params.id)

return res.status(200).send({msg:"Pedido eliminado"});

}

const updateOrder = async (req: Request, res: Response) => {

const { id } = req.params

const {_id,user, ...other} = req.body

//lo actualizamos
try{
await Order.findByIdAndUpdate(id, other)
return res.status(200).send({msg:"Pedido actualizado"});
} catch (e){
console.log(e);
res.status(400).send({msg: e});
}
}

const addOrder = async (req: Request, res: Response) => {
const orderData = req.body;

//creamos nuevo producto
const order = new Order({
user:orderData.user,
products: orderData.products,
order_date: orderData.order_date,
status: orderData.status,
shipping_address: orderData.shipping_address
});

//lo guardamos
try{
await order.save()
return res.status(200).send(order);
} catch (e){
console.log(e);
res.status(400).send({msg:"Pedido no añadido"});
}
}

module.exports = {
addOrder,
findAllOrders,
findOrder,
findOrderByClient,
updateOrder,
deleteOrder
}
Loading

0 comments on commit 6344515

Please sign in to comment.