diff --git a/semana15/Express/.gitignore b/semana15/Express/.gitignore new file mode 100644 index 0000000..a049075 --- /dev/null +++ b/semana15/Express/.gitignore @@ -0,0 +1,3 @@ +node_modules +package-lock.json +build \ No newline at end of file diff --git a/semana15/Express/package.json b/semana15/Express/package.json new file mode 100644 index 0000000..7f71dd6 --- /dev/null +++ b/semana15/Express/package.json @@ -0,0 +1,27 @@ +{ + "name": "Express", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "dev": "ts-node-dev ./src/index.ts", + "start": "tsc && node ./build/index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "@types/cors": "^2.8.10", + "@types/express": "^4.17.11", + "concurrently": "^6.0.0", + "nodemon": "^2.0.7", + "ts-node-dev": "^1.1.6", + "typescript": "^4.2.3" + }, + "dependencies": { + "cors": "^2.8.5", + "express": "^4.17.1", + "ts-node": "^9.1.1" + } +} diff --git a/semana15/Express/src/countries.ts b/semana15/Express/src/countries.ts new file mode 100644 index 0000000..3c42d8a --- /dev/null +++ b/semana15/Express/src/countries.ts @@ -0,0 +1,1199 @@ +export enum CONTINENTS { + AFRICA = "África", + AMERICA = "América", + ASIA = "Ásia", + EUROPE = "Europa", + OCEANIA = "Oceania" + } + + export type country = { + id: number, + name: string, + capital: string, + continent: CONTINENTS + } + + export const countries: country[] = [ + { + "id": 0, + "name": "África do Sul", + "capital": "Pretória", + "continent": CONTINENTS.AFRICA + }, + { + "id": 1, + "name": "Angola", + "capital": "Luanda", + "continent": CONTINENTS.AFRICA + }, + { + "id": 2, + "name": "Argélia", + "capital": "Argel", + "continent": CONTINENTS.AFRICA + }, + { + "id": 3, + "name": "Benim", + "capital": "Porto Novo", + "continent": CONTINENTS.AFRICA + }, + { + "id": 4, + "name": "Botsuana", + "capital": "Gaborone", + "continent": CONTINENTS.AFRICA + }, + { + "id": 5, + "name": "Burquina Faso", + "capital": "Uagadugu", + "continent": CONTINENTS.AFRICA + }, + { + "id": 6, + "name": "Burúndi", + "capital": "Bujumbura", + "continent": CONTINENTS.AFRICA + }, + { + "id": 7, + "name": "Cabo Verde", + "capital": "Praia", + "continent": CONTINENTS.AFRICA + }, + { + "id": 8, + "name": "Camarões", + "capital": "Iaundé", + "continent": CONTINENTS.AFRICA + }, + { + "id": 9, + "name": "Chade", + "capital": "Jamena", + "continent": CONTINENTS.AFRICA + }, + { + "id": 10, + "name": "Comores", + "capital": "Moroni", + "continent": CONTINENTS.AFRICA + }, + { + "id": 11, + "name": "Congo-Brazzaville", + "capital": "Brazavile", + "continent": CONTINENTS.AFRICA + }, + { + "id": 12, + "name": "Costa do Marfim", + "capital": "Iamussucro", + "continent": CONTINENTS.AFRICA + }, + { + "id": 13, + "name": "Egito", + "capital": "Cairo", + "continent": CONTINENTS.AFRICA + }, + { + "id": 14, + "name": "Eritreia", + "capital": "Asmara", + "continent": CONTINENTS.AFRICA + }, + { + "id": 15, + "name": "Etiópia", + "capital": "Adis Abeba", + "continent": CONTINENTS.AFRICA + }, + { + "id": 16, + "name": "Gabão", + "capital": "Libreville", + "continent": CONTINENTS.AFRICA + }, + { + "id": 17, + "name": "Gâmbia", + "capital": "Banjul", + "continent": CONTINENTS.AFRICA + }, + { + "id": 18, + "name": "Gana", + "capital": "Acra", + "continent": CONTINENTS.AFRICA + }, + { + "id": 19, + "name": "Guiné", + "capital": "Conacri", + "continent": CONTINENTS.AFRICA + }, + { + "id": 20, + "name": "Guiné Equatorial", + "capital": "Malabo", + "continent": CONTINENTS.AFRICA + }, + { + "id": 21, + "name": "Guiné-Bissau", + "capital": "Bissau", + "continent": CONTINENTS.AFRICA + }, + { + "id": 22, + "name": "Jibuti", + "capital": "Jibuti", + "continent": CONTINENTS.AFRICA + }, + { + "id": 23, + "name": "Lesoto", + "capital": "Maseru", + "continent": CONTINENTS.AFRICA + }, + { + "id": 24, + "name": "Libéria", + "capital": "Monróvia", + "continent": CONTINENTS.AFRICA + }, + { + "id": 25, + "name": "Líbia", + "capital": "Trípoli", + "continent": CONTINENTS.AFRICA + }, + { + "id": 26, + "name": "Madagáscar", + "capital": "Antananarivo", + "continent": CONTINENTS.AFRICA + }, + { + "id": 27, + "name": "Maláui", + "capital": "Lilôngue", + "continent": CONTINENTS.AFRICA + }, + { + "id": 28, + "name": "Mali", + "capital": "Bamaco", + "continent": CONTINENTS.AFRICA + }, + { + "id": 29, + "name": "Marrocos", + "capital": "Rebate", + "continent": CONTINENTS.AFRICA + }, + { + "id": 30, + "name": "Maurícia", + "capital": "Porto Luís", + "continent": CONTINENTS.AFRICA + }, + { + "id": 31, + "name": "Mauritânia", + "capital": "Nuaquechote", + "continent": CONTINENTS.AFRICA + }, + { + "id": 32, + "name": "Moçambique", + "capital": "Maputo", + "continent": CONTINENTS.AFRICA + }, + { + "id": 33, + "name": "Namíbia", + "capital": "Vinduque", + "continent": CONTINENTS.AFRICA + }, + { + "id": 34, + "name": "Níger", + "capital": "Niamei", + "continent": CONTINENTS.AFRICA + }, + { + "id": 35, + "name": "Nigéria", + "capital": "Abuja", + "continent": CONTINENTS.AFRICA + }, + { + "id": 36, + "name": "Quénia", + "capital": "Nairóbi", + "continent": CONTINENTS.AFRICA + }, + { + "id": 37, + "name": "República Centro-Africana", + "capital": "Bangui", + "continent": CONTINENTS.AFRICA + }, + { + "id": 38, + "name": "República Democrática do Congo", + "capital": "Quinxassa", + "continent": CONTINENTS.AFRICA + }, + { + "id": 39, + "name": "Ruanda", + "capital": "Quigali", + "continent": CONTINENTS.AFRICA + }, + { + "id": 40, + "name": "São Tomé e Príncipe", + "capital": "São Tomé", + "continent": CONTINENTS.AFRICA + }, + { + "id": 41, + "name": "Seicheles", + "capital": "Vitória", + "continent": CONTINENTS.AFRICA + }, + { + "id": 42, + "name": "Senegal", + "capital": "Dacar", + "continent": CONTINENTS.AFRICA + }, + { + "id": 43, + "name": "Serra Leoa", + "capital": "Freetown", + "continent": CONTINENTS.AFRICA + }, + { + "id": 44, + "name": "Somália", + "capital": "Mogadíscio", + "continent": CONTINENTS.AFRICA + }, + { + "id": 45, + "name": "Suazilândia", + "capital": "Lobamba", + "continent": CONTINENTS.AFRICA + }, + { + "id": 46, + "name": "Sudão", + "capital": "Cartum", + "continent": CONTINENTS.AFRICA + }, + { + "id": 47, + "name": "Sudão do Sul", + "capital": "Juba", + "continent": CONTINENTS.AFRICA + }, + { + "id": 48, + "name": "Tanzânia", + "capital": "Dodoma", + "continent": CONTINENTS.AFRICA + }, + { + "id": 49, + "name": "Togo", + "capital": "Lomé", + "continent": CONTINENTS.AFRICA + }, + { + "id": 50, + "name": "Tunísia", + "capital": "Tunes", + "continent": CONTINENTS.AFRICA + }, + { + "id": 51, + "name": "Uganda", + "capital": "Campala", + "continent": CONTINENTS.AFRICA + }, + { + "id": 52, + "name": "Zâmbia", + "capital": "Lusaca", + "continent": CONTINENTS.AFRICA + }, + { + "id": 53, + "name": "Zimbábue", + "capital": "Harare", + "continent": CONTINENTS.AFRICA + }, + { + "id": 54, + "name": "Antiga e Barbuda", + "capital": "São João", + "continent": CONTINENTS.AMERICA + }, + { + "id": 55, + "name": "Argentina", + "capital": "Buenos Aires", + "continent": CONTINENTS.AMERICA + }, + { + "id": 56, + "name": "Bahamas", + "capital": "Nassau", + "continent": CONTINENTS.AMERICA + }, + { + "id": 57, + "name": "Barbados", + "capital": "Bridgetown", + "continent": CONTINENTS.AMERICA + }, + { + "id": 58, + "name": "Belize", + "capital": "Belmopã", + "continent": CONTINENTS.AMERICA + }, + { + "id": 59, + "name": "Bolívia", + "capital": "Sucre", + "continent": CONTINENTS.AMERICA + }, + { + "id": 60, + "name": "Brasil", + "capital": "Brasília", + "continent": CONTINENTS.AMERICA + }, + { + "id": 61, + "name": "Canadá", + "capital": "Otava", + "continent": CONTINENTS.AMERICA + }, + { + "id": 62, + "name": "Chile", + "capital": "Santiago", + "continent": CONTINENTS.AMERICA + }, + { + "id": 63, + "name": "Colômbia", + "capital": "Bogotá", + "continent": CONTINENTS.AMERICA + }, + { + "id": 64, + "name": "Costa Rica", + "capital": "São José", + "continent": CONTINENTS.AMERICA + }, + { + "id": 65, + "name": "Cuba", + "capital": "Havana", + "continent": CONTINENTS.AMERICA + }, + { + "id": 66, + "name": "Dominica", + "capital": "Roseau", + "continent": CONTINENTS.AMERICA + }, + { + "id": 67, + "name": "Equador", + "capital": "Quito", + "continent": CONTINENTS.AMERICA + }, + { + "id": 68, + "name": "Estados Unidos", + "capital": "Washington, D.C.", + "continent": CONTINENTS.AMERICA + }, + { + "id": 69, + "name": "Granada", + "capital": "São Jorge", + "continent": CONTINENTS.AMERICA + }, + { + "id": 70, + "name": "Guatemala", + "capital": "Cidade da Guatemala", + "continent": CONTINENTS.AMERICA + }, + { + "id": 71, + "name": "Guiana", + "capital": "Georgetown", + "continent": CONTINENTS.AMERICA + }, + { + "id": 72, + "name": "Haiti", + "capital": "Porto Príncipe", + "continent": CONTINENTS.AMERICA + }, + { + "id": 73, + "name": "Honduras", + "capital": "Tegucigalpa", + "continent": CONTINENTS.AMERICA + }, + { + "id": 74, + "name": "Jamaica", + "capital": "Kingston", + "continent": CONTINENTS.AMERICA + }, + { + "id": 75, + "name": "México", + "capital": "Cidade do México", + "continent": CONTINENTS.AMERICA + }, + { + "id": 76, + "name": "Nicarágua", + "capital": "Manágua", + "continent": CONTINENTS.AMERICA + }, + { + "id": 77, + "name": "Panamá", + "capital": "Cidade do Panamá", + "continent": CONTINENTS.AMERICA + }, + { + "id": 78, + "name": "Paraguai", + "capital": "Assunção", + "continent": CONTINENTS.AMERICA + }, + { + "id": 79, + "name": "Peru", + "capital": "Lima", + "continent": CONTINENTS.AMERICA + }, + { + "id": 80, + "name": "República Dominicana", + "capital": "São Domingos", + "continent": CONTINENTS.AMERICA + }, + { + "id": 81, + "name": "Salvador", + "capital": "São Salvador", + "continent": CONTINENTS.AMERICA + }, + { + "id": 82, + "name": "Santa Lúcia", + "capital": "Castries", + "continent": CONTINENTS.AMERICA + }, + { + "id": 83, + "name": "São Cristóvão e Neves", + "capital": "Basseterre", + "continent": CONTINENTS.AMERICA + }, + { + "id": 84, + "name": "São Vicente e Granadinas", + "capital": "Kingstown", + "continent": CONTINENTS.AMERICA + }, + { + "id": 85, + "name": "Suriname", + "capital": "Paramaribo", + "continent": CONTINENTS.AMERICA + }, + { + "id": 86, + "name": "Trindade e Tobago", + "capital": "Porto de Espanha", + "continent": CONTINENTS.AMERICA + }, + { + "id": 87, + "name": "Uruguai", + "capital": "Montevideu", + "continent": CONTINENTS.AMERICA + }, + { + "id": 88, + "name": "Venezuela", + "capital": "Caracas", + "continent": CONTINENTS.AMERICA + }, + { + "id": 89, + "name": "Afeganistão", + "capital": "Cabul", + "continent": CONTINENTS.ASIA + }, + { + "id": 90, + "name": "Arábia Saudita", + "capital": "Riade", + "continent": CONTINENTS.ASIA + }, + { + "id": 91, + "name": "Arménia", + "capital": "Erevã", + "continent": CONTINENTS.ASIA + }, + { + "id": 92, + "name": "Azerbaijão", + "capital": "Bacu", + "continent": CONTINENTS.ASIA + }, + { + "id": 93, + "name": "Bangladexe", + "capital": "Daca", + "continent": CONTINENTS.ASIA + }, + { + "id": 94, + "name": "Barém", + "capital": "Manama", + "continent": CONTINENTS.ASIA + }, + { + "id": 95, + "name": "Brunei", + "capital": "Bandar Seri Begauã", + "continent": CONTINENTS.ASIA + }, + { + "id": 96, + "name": "Butão", + "capital": "Timbu", + "continent": CONTINENTS.ASIA + }, + { + "id": 97, + "name": "Camboja", + "capital": "Pnom Pene", + "continent": CONTINENTS.ASIA + }, + { + "id": 98, + "name": "Catar", + "capital": "Doa", + "continent": CONTINENTS.ASIA + }, + { + "id": 99, + "name": "Cazaquistão", + "capital": "Astana", + "continent": CONTINENTS.ASIA + }, + { + "id": 100, + "name": "China", + "capital": "Pequim", + "continent": CONTINENTS.ASIA + }, + { + "id": 101, + "name": "Coreia do Norte", + "capital": "Pionguiangue", + "continent": CONTINENTS.ASIA + }, + { + "id": 102, + "name": "Coreia do Sul", + "capital": "Seul", + "continent": CONTINENTS.ASIA + }, + { + "id": 103, + "name": "Cuaite", + "capital": "Cidade do Cuaite", + "continent": CONTINENTS.ASIA + }, + { + "id": 104, + "name": "Emirados Árabes Unidos", + "capital": "Abu Dabi", + "continent": CONTINENTS.ASIA + }, + { + "id": 105, + "name": "Estado da Palestina", + "capital": "Jerusalém Oriental", + "continent": CONTINENTS.ASIA + }, + { + "id": 106, + "name": "Filipinas", + "capital": "Manila", + "continent": CONTINENTS.ASIA + }, + { + "id": 107, + "name": "Geórgia", + "capital": "Tebilíssi", + "continent": CONTINENTS.ASIA + }, + { + "id": 108, + "name": "Iémen", + "capital": "Saná", + "continent": CONTINENTS.ASIA + }, + { + "id": 109, + "name": "Índia", + "capital": "Nova Déli", + "continent": CONTINENTS.ASIA + }, + { + "id": 110, + "name": "Indonésia", + "capital": "Jacarta", + "continent": CONTINENTS.ASIA + }, + { + "id": 111, + "name": "Irão", + "capital": "Teerão", + "continent": CONTINENTS.ASIA + }, + { + "id": 112, + "name": "Iraque", + "capital": "Bagdade", + "continent": CONTINENTS.ASIA + }, + { + "id": 113, + "name": "Israel", + "capital": "Jerusalém", + "continent": CONTINENTS.ASIA + }, + { + "id": 114, + "name": "Japão", + "capital": "Tóquio", + "continent": CONTINENTS.ASIA + }, + { + "id": 115, + "name": "Jordânia", + "capital": "Amã", + "continent": CONTINENTS.ASIA + }, + { + "id": 116, + "name": "Laus", + "capital": "Vienciana", + "continent": CONTINENTS.ASIA + }, + { + "id": 117, + "name": "Líbano", + "capital": "Beirute", + "continent": CONTINENTS.ASIA + }, + { + "id": 118, + "name": "Malásia", + "capital": "Cuala Lumpur", + "continent": CONTINENTS.ASIA + }, + { + "id": 119, + "name": "Maldivas", + "capital": "Malé", + "continent": CONTINENTS.ASIA + }, + { + "id": 120, + "name": "Mianmar", + "capital": "Nepiedó", + "continent": CONTINENTS.ASIA + }, + { + "id": 121, + "name": "Mongólia", + "capital": "Ulã Bator", + "continent": CONTINENTS.ASIA + }, + { + "id": 122, + "name": "Nepal", + "capital": "Catmandu", + "continent": CONTINENTS.ASIA + }, + { + "id": 123, + "name": "Omã", + "capital": "Mascate", + "continent": CONTINENTS.ASIA + }, + { + "id": 124, + "name": "Paquistão", + "capital": "Islamabade", + "continent": CONTINENTS.ASIA + }, + { + "id": 125, + "name": "Quirguistão", + "capital": "Bisqueque", + "continent": CONTINENTS.ASIA + }, + { + "id": 126, + "name": "Singapura", + "capital": "Singapura", + "continent": CONTINENTS.ASIA + }, + { + "id": 127, + "name": "Síria", + "capital": "Damasco", + "continent": CONTINENTS.ASIA + }, + { + "id": 128, + "name": "Sri Lanca", + "capital": "Sri Jaiavardenapura-Cota", + "continent": CONTINENTS.ASIA + }, + { + "id": 129, + "name": "Tailândia", + "capital": "Banguecoque", + "continent": CONTINENTS.ASIA + }, + { + "id": 130, + "name": "Taiuã", + "capital": "Taipé", + "continent": CONTINENTS.ASIA + }, + { + "id": 131, + "name": "Tajiquistão", + "capital": "Duchambé", + "continent": CONTINENTS.ASIA + }, + { + "id": 132, + "name": "Turcomenistão", + "capital": "Asgabate", + "continent": CONTINENTS.ASIA + }, + { + "id": 133, + "name": "Turquia", + "capital": "Ancara", + "continent": CONTINENTS.ASIA + }, + { + "id": 134, + "name": "Usbequistão", + "capital": "Tasquente", + "continent": CONTINENTS.ASIA + }, + { + "id": 135, + "name": "Vietname", + "capital": "Hanói", + "continent": CONTINENTS.ASIA + }, + { + "id": 136, + "name": "Albânia", + "capital": "Tirana", + "continent": CONTINENTS.EUROPE + }, + { + "id": 137, + "name": "Alemanha", + "capital": "Berlim", + "continent": CONTINENTS.EUROPE + }, + { + "id": 138, + "name": "Andorra", + "capital": "Andorra-a-Velha", + "continent": CONTINENTS.EUROPE + }, + { + "id": 139, + "name": "Áustria", + "capital": "Viena", + "continent": CONTINENTS.EUROPE + }, + { + "id": 140, + "name": "Bélgica", + "capital": "Bruxelas", + "continent": CONTINENTS.EUROPE + }, + { + "id": 141, + "name": "Bielorrússia", + "capital": "Minsque", + "continent": CONTINENTS.EUROPE + }, + { + "id": 142, + "name": "Bósnia e Herzegovina", + "capital": "Saraievo", + "continent": CONTINENTS.EUROPE + }, + { + "id": 143, + "name": "Bulgária", + "capital": "Sófia", + "continent": CONTINENTS.EUROPE + }, + { + "id": 144, + "name": "Chipre", + "capital": "Nicósia", + "continent": CONTINENTS.EUROPE + }, + { + "id": 145, + "name": "Cosovo", + "capital": "Pristina", + "continent": CONTINENTS.EUROPE + }, + { + "id": 146, + "name": "Croácia", + "capital": "Zagrebe", + "continent": CONTINENTS.EUROPE + }, + { + "id": 147, + "name": "Dinamarca", + "capital": "Copenhaga", + "continent": CONTINENTS.EUROPE + }, + { + "id": 148, + "name": "Eslováquia", + "capital": "Bratislava", + "continent": CONTINENTS.EUROPE + }, + { + "id": 149, + "name": "Eslovénia", + "capital": "Liubliana", + "continent": CONTINENTS.EUROPE + }, + { + "id": 150, + "name": "Espanha", + "capital": "Madrid", + "continent": CONTINENTS.EUROPE + }, + { + "id": 151, + "name": "Estónia", + "capital": "Talim", + "continent": CONTINENTS.EUROPE + }, + { + "id": 152, + "name": "Finlândia", + "capital": "Helsínquia", + "continent": CONTINENTS.EUROPE + }, + { + "id": 153, + "name": "França", + "capital": "Paris", + "continent": CONTINENTS.EUROPE + }, + { + "id": 154, + "name": "Grécia", + "capital": "Atenas", + "continent": CONTINENTS.EUROPE + }, + { + "id": 155, + "name": "Hungria", + "capital": "Budapeste", + "continent": CONTINENTS.EUROPE + }, + { + "id": 156, + "name": "Irlanda", + "capital": "Dublim", + "continent": CONTINENTS.EUROPE + }, + { + "id": 157, + "name": "Islândia", + "capital": "Reiquiavique", + "continent": CONTINENTS.EUROPE + }, + { + "id": 158, + "name": "Itália", + "capital": "Roma", + "continent": CONTINENTS.EUROPE + }, + { + "id": 159, + "name": "Letónia", + "capital": "Riga", + "continent": CONTINENTS.EUROPE + }, + { + "id": 160, + "name": "Listenstaine", + "capital": "Vaduz", + "continent": CONTINENTS.EUROPE + }, + { + "id": 161, + "name": "Lituânia", + "capital": "Vílnius", + "continent": CONTINENTS.EUROPE + }, + { + "id": 162, + "name": "Luxemburgo", + "capital": "Luxemburgo", + "continent": CONTINENTS.EUROPE + }, + { + "id": 163, + "name": "Macedónia", + "capital": "Escópia", + "continent": CONTINENTS.EUROPE + }, + { + "id": 164, + "name": "Malta", + "capital": "Valeta", + "continent": CONTINENTS.EUROPE + }, + { + "id": 165, + "name": "Moldávia", + "capital": "Quixinau", + "continent": CONTINENTS.EUROPE + }, + { + "id": 166, + "name": "Mónaco", + "capital": "Mónaco", + "continent": CONTINENTS.EUROPE + }, + { + "id": 167, + "name": "Montenegro", + "capital": "Podgoritsa", + "continent": CONTINENTS.EUROPE + }, + { + "id": 168, + "name": "Noruega", + "capital": "Oslo", + "continent": CONTINENTS.EUROPE + }, + { + "id": 169, + "name": "Países Baixos", + "capital": "Amesterdão", + "continent": CONTINENTS.EUROPE + }, + { + "id": 170, + "name": "Polónia", + "capital": "Varsóvia", + "continent": CONTINENTS.EUROPE + }, + { + "id": 171, + "name": "Portugal", + "capital": "Lisboa", + "continent": CONTINENTS.EUROPE + }, + { + "id": 172, + "name": "Reino Unido", + "capital": "Londres", + "continent": CONTINENTS.EUROPE + }, + { + "id": 173, + "name": "República Checa", + "capital": "Praga", + "continent": CONTINENTS.EUROPE + }, + { + "id": 174, + "name": "Roménia", + "capital": "Bucareste", + "continent": CONTINENTS.EUROPE + }, + { + "id": 175, + "name": "Rússia", + "capital": "Moscovo", + "continent": CONTINENTS.EUROPE + }, + { + "id": 176, + "name": "São Marinho", + "capital": "São Marinho", + "continent": CONTINENTS.EUROPE + }, + { + "id": 177, + "name": "Sérvia", + "capital": "Belgrado", + "continent": CONTINENTS.EUROPE + }, + { + "id": 178, + "name": "Suécia", + "capital": "Estocolmo", + "continent": CONTINENTS.EUROPE + }, + { + "id": 179, + "name": "Suíça", + "capital": "Berna", + "continent": CONTINENTS.EUROPE + }, + { + "id": 180, + "name": "Ucrânia", + "capital": "Quieve", + "continent": CONTINENTS.EUROPE + }, + { + "id": 181, + "name": "Vaticano", + "capital": "Vaticano", + "continent": CONTINENTS.EUROPE + }, + { + "id": 182, + "name": "Austrália", + "capital": "Camberra", + "continent": CONTINENTS.OCEANIA + }, + { + "id": 183, + "name": "Fiji", + "capital": "Suva", + "continent": CONTINENTS.OCEANIA + }, + { + "id": 184, + "name": "Ilhas Marechal", + "capital": "Majuro", + "continent": CONTINENTS.OCEANIA + }, + { + "id": 185, + "name": "Micronésia", + "capital": "Paliquir", + "continent": CONTINENTS.OCEANIA + }, + { + "id": 186, + "name": "Nauru", + "capital": "Iarém", + "continent": CONTINENTS.OCEANIA + }, + { + "id": 187, + "name": "Nova Zelândia", + "capital": "Wellington", + "continent": CONTINENTS.OCEANIA + }, + { + "id": 188, + "name": "Palau", + "capital": "Ngerulmud", + "continent": CONTINENTS.OCEANIA + }, + { + "id": 189, + "name": "Papua Nova Guiné", + "capital": "Porto Moresby", + "continent": CONTINENTS.OCEANIA + }, + { + "id": 190, + "name": "Quiribáti", + "capital": "Taraua do Sul", + "continent": CONTINENTS.OCEANIA + }, + { + "id": 191, + "name": "Salomão", + "capital": "Honiara", + "continent": CONTINENTS.OCEANIA + }, + { + "id": 192, + "name": "Samoa", + "capital": "Apia", + "continent": CONTINENTS.OCEANIA + }, + { + "id": 193, + "name": "Timor-Leste", + "capital": "Díli", + "continent": CONTINENTS.OCEANIA + }, + { + "id": 194, + "name": "Tonga", + "capital": "Nucualofa", + "continent": CONTINENTS.OCEANIA + }, + { + "id": 195, + "name": "Tuvalu", + "capital": "Funafuti", + "continent": CONTINENTS.OCEANIA + }, + { + "id": 196, + "name": "Vanuatu", + "capital": "Porto Vila", + "continent": CONTINENTS.OCEANIA + } + ] \ No newline at end of file diff --git a/semana15/Express/src/index.ts b/semana15/Express/src/index.ts new file mode 100644 index 0000000..7ace10d --- /dev/null +++ b/semana15/Express/src/index.ts @@ -0,0 +1,87 @@ +import express, { Request, Response } from 'express'; +import cors from 'cors'; +import { AddressInfo } from "net" +import { countries, country } from "./countries" + +const app = express(); + +app.use(express.json()); +app.use(cors()); + +app.get('/', (req: Request, res: Response) => { + res.json({ + message: 'Hello World!' + }); +}); + +app.get("/countries/all", (req: Request, res: Response) => { + const result = countries.map(country => ({ + id: country.id, + name: country.name + })) + + res + .status(200) + .send(result) +}) + + +app.get("/countries/search", (req: Request, res: Response) => { + let result: country[] = countries; + try { + if (!req.query.name && !req.query.capital && !req.query.continent) { + throw new Error("Invalid Parameters"); + } + if (req.query.name) { + result = result.filter( + country => country.name.includes(req.query.name as string) + ) + } + if (req.query.capital) { + result = result.filter( + country => country.capital.includes(req.query.capital as string) + ) + } + if (req.query.continent) { + result = result.filter( + country => country.continent.includes(req.query.continent as string) + ) + } + } catch (error) { + res.status(400).send(error.message); + } + res.status(200).send(result); + }); + + app.get("/countries/:id", (req: Request, res: Response) => { + + const result = countries.find( + country => country.id === Number(req.params.id) + ) + + if (result) { + res.status(200).send(result) + } else { + res.status(404).send("Not found") + } + + }) + + app.put("/countries/edit/:id", (req: Request, res: Response) => { + + const result = countries.find( + country => country.id === Number(req.params.id) + ) + + + + }) + +const server = app.listen(process.env.PORT || 3003, () => { + if (server) { + const address = server.address() as AddressInfo; + console.log(`Server is running in http://localhost:${address.port}`) + } else { + console.error(`Failure upon starting server.`) + } +}) \ No newline at end of file diff --git a/semana15/Express/tsconfig.json b/semana15/Express/tsconfig.json new file mode 100644 index 0000000..e124967 --- /dev/null +++ b/semana15/Express/tsconfig.json @@ -0,0 +1,71 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ + // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "./build", /* Redirect output structure to the directory. */ + "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "skipLibCheck": true, /* Skip type checking of declaration files. */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +}