category.js 2.06 KB
var express = require('express');
var router = express.Router();
var request = require('request');
require('dotenv').config();

/* GET home page. */
let GU_CODE;
let ANIMAL_INFO_API_KEY = process.env.ANIMAL_API_KEY;
let user_gu;
let user_latitude;
let user_longitude;

router.get('/hospital', function (req, res) {
    let institute_url = 'http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03';
    let qs = `?KEY=${GYEONGI_API_KEY}&SIGUN_CD=${SIGUN_CODE}&Type=json`;
    request({
        url: library_url + qs,
        method: 'GET'
    }, function (err, response, body) {
        if (!err && res.statusCode == 200) {
            let library_result = JSON.parse(body);
            let librarys = [];
            for (let i = 0; i < library_result.Tbggibllbrm[1].row.length; i++) {
                library = library_result.Tbggibllbrm[1].row[i];
                if (userArea(library, 'REFINE_LOTNO_ADDR', user_target)) {
                    librarys.push(library);
                }
            }
            library_grade = evalGrade(library_A, 0.5, librarys.length);
            request({
                url: institute_url + qs,
                method: 'GET'
            }, function (err, response, body) {
                if (!err && res.statusCode == 200) {
                    let institute_result = JSON.parse(body);
                    let institutes = [];
                    for (let i = 0; i < institute_result.TninsttInstutM[1].row.length; i++) {
                        institute = institute_result.TninsttInstutM[1].row[i];
                        if (userArea(institute, 'REFINE_LOTNO_ADDR', user_target)) {
                            institutes.push(institute);
                        }
                    }
                    institute_grade = evalGrade(institute_A, institute_B, institutes);
                    grade = avgGrade(library_grade, institute_grade);
                    res.render('result', { category: 'school', librarys: librarys, institutes: institutes, userLocation: userLocation, grade: grade });
                }
            })
        }
    })
});