- Create a folder in projects and start a new project using npm called exchange_rate inside this folder
- Create a NodeJS file to consume the above API. https://economia.awesomeapi.com.br/json/list/USD-BRL/1
PS: the last param is related with the amount of the last days we want to get. 1 = today.
- The output of the code on console, should be the following:
Cotação USD - BRL
Name:
High value: R$ xx,xx
Low value: R$ xx,xx
BID: R$ xx,xx
Day Average: R$ xx,xx
Last 2 days average: R$ xx,xx
Rules:
- Take careful with the decimal number conversion
- To calculate Day Average use the formula: Day Average = (high_value + low_value) / 2
- To calculate the Last 2 days average use: (today average + yesterday average) / 2
This exercise is using the graphql-bff project inside packages.
- To start the bff-graphql project run docker-compose up --build inside the folder
Inside the bff project you must:
- Create an endpoint to get a tweet by ID and returning the Author user together, as the following example:
{
"id": "1",
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque volutpat sit amet dolor et porttitor. Integer venenatis leo ut nullam. ",
"author": {
"id": "1",
"completeName": "Bárbara Becker",
"age": 20
},
"date": "2019-10-25T23:45:35.116Z"
}
- Create an endpoint to get a list of tweets from an specif user and returning as the following object:
{
"id": "1",
"completeName": "Bárbara Becker",
"age": 20,
tweets: [
{
"id": "1",
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque volutpat sit amet dolor et porttitor. Integer venenatis leo ut nullam. ",
"date": "2019-10-25T23:45:35.116Z"
},
{
"id": "2",
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque volutpat sit amet dolor et porttitor. Integer venenatis leo ut nullam. ",
"date": "2019-10-25T23:45:35.116Z"
}
]
}
3. Implement an endpoint to get all the retired users (age > 70)
Use the data provider by the JSON-server (DOC: https://github.com/typicode/json-server)
- Enter in http://localhost:3000/graphql and see the api documentation and what queries you can make
- Inside the graphql project, in the schema file, create another entry in the rootQuery object for the company list just like the user rootQuery
- Create a type for Tweets as following:
type Tweet {
id: ID!
body: String
date: Date
Author: UserType
}
- Modify the UserType to get a list of Tweets
- Create a rootQuery for tweet and tweet list
- Test what you did
- Clone the project https://github.com/johnpapa/angular-tour-of-heroes and npm install inside the project
- Inside the project run ng build --prod
- Check the dist/index.html was the entire mounted? why?
- Now run the application with ng serve --prod
- Run the audit with default configuration and take a print from the result
- Commit your frontend project
- Give the ng cli command to add SSR schema in the project
ng add @nguniversal/express-engine --clientProject angular.io-example
- Check the changes and what the command did
- Run the project with "npm run build:ssr && npm run serve:ssr"
- Run the audit again and compare the results
- Now install the compress package
npm install --save compress
- Import the compress inside server.ts
import * as compression from 'compression';
- Inside the server.ts after app.set add the following line
app.use(compression())
- Run step 9 and 10 again
- Create a new project with ng-cli
- Create a module called shared
- Create a component called users
- Create a component called tweets
- Create routes for users and tweets with the related components
- Create a header using bootstrap with links for users and tweets
- Create an userService and tweetsService with methods getUsers and getTweets (use the json server) or create the endpoints in the bff if you have time
- With results of getUsers and getTweets present in the users and tweets components using bootstrap cards
- Create a list component or list-item component in shared and replace the common logic in tweets and users components your shared component
- Install dependencies:
npm install bootstrap jquery popper.js --save
- Update array styles in angular.json
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.css",
"src/styles.scss"
],
- Update array scripts in angular.json
"scripts": [
"node_modules/jquery/dist/jquery.js",
"node_modules/popper.js/dist/umd/popper.js",
"node_modules/bootstrap/dist/js/bootstrap.js"
],
- Run in 1 terminal:
npm run apis
- Run in another terminal
npm start
- To login the page see the username inside mocks/db.json and see the user array. The password is not necessary
- If we try to access the route /authenticated-area without login, it will work. Fix this using guard. (use the auth.service)
- Restrict the /admin area to only users logged with the role admin (db.json) - create another guard for this