API Covid19

  • Listar número de novos casos (para todos os dias da semana)
  • Lista número de internamentos nos Cuidados Intensivos (para todos os dias da semana)
  • Dia com mais novos casos
  • Dia com menos casos
  • Média a 7 dias
  • Número total de novos casos na semana
Criação da BD
//Import Covid ModelCovid = require('./RegistoModel');//Para indexexports.index = function (req, res) {var arrayCasos = [];var darrayData = [];var totalCasos = 0;var arrayIntensivos = [];Covid.get(function (err, covid) {if (err)res.json({status: "error",message: err});for(var i=0; i<covid.length; i++){arrayCasos.push(covid[i].confirmados_novos)arrayIntensivos.push(covid[i].internados_uci)darrayData.push(covid[i].data)totalCasos += Number(covid[i].confirmados_novos);}var maximo = null;maximo = Math.max(...arrayCasos);var IndiceMax = arrayCasos.indexOf(maximo);var minimo = null;minimo = Math.min(...arrayCasos);var IndiceMin = arrayCasos.indexOf(minimo);var media = null;media = totalCasos/covid.length;res.json({novosCasos: arrayCasos,internadosUCI: arrayIntensivos,Maximo: darrayData[IndiceMax],Minimo: darrayData[IndiceMin],totalCasos: totalCasos,Media: media,});});};//Criar nova BIOexports.add = function (req, res) {var covid = new Covid();covid.data = req.body.data? req.body.data: covid.data;covid.confirmados_novos = req.body.confirmados_novos;covid.internados_uci = req.body.internados_uci;//Guardar e verificar erroscovid.save(function (err) {if (err)res.json(err);res.json({message: "Nova Covid Adicionada!",data: covid});});};// Ver Covidexports.view = function (req, res) {Covid.findById(req.params.covid_id, function (err, covid) {if (err)res.send(err);res.json({message: 'Detalhes da Covid',data: covid});});};// Atualizar Covidexports.update = function (req, res) {Covid.findById(req.params.covid_id, function (err, covid) {if (err)res.send(err);covid.nome = req.body.nome ? req.body.nome : covid.nome;covid.email = req.body.email;covid.telef = req.body.telef;covid.morada = req.body.morada;//Guardar e verificar erroscovid.save(function (err) {if (err)res.json(err)res.json({message: "Covid Updated Successfully",data: covid});});});};// Apagar Covidexports.delete = function (req, res) {Covid.deleteOne({_id: req.params.covid_id}, function (err, contact) {if (err)res.send(err)res.json({status: "OK",message: 'Covid Eliminada!'});});};




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Ionic 4 and the Lifecycle Hooks

How to avoid memory leaks from services communication in Angular ?

Creating a GraphQL API with Apollo Server

Build your first Node API and Express

Bring the power of the Google Assistant to your command line.

Handling loading and error state in React application and clean state mess.

React state management. clean sate mess, loading and error handling in react

Ensure efficient development and deployment of a high-quality hospital app using React Native

Introducing React Navigation 5

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
João Saraiva

João Saraiva

More from Medium

Sending Requests with Postman Part-1 GET

That JS Buddy

Learning binary exploitation — 2

How to Install Java on Windows 11? Here Is a Detailed Tutorial