// DEBUG... COMENTAR DEPOIS //_log.info('service called...'); //const astroType = _req.getString("astroType"); //_log.info(astroType) const aroundAstroUid = _req.getString("aroundAstroUid"); //_log.info("AroundAstroUid: ", aroundAstroUid); //DEBUG - simulate slow server - DONT FORGET TO COMMENT //_log.info("Slow server..."); //_exec.sleep(3000); /* const page = _req.getInt("page", 1); let offset = (page - 1) * 8; if (offset < 0) { offset = 0; } let filterWhere = ""; const filterParams = _val.list() if (astroType != "" && astroType != "all") { filterWhere = " AND astro_type.uid = CAST(? AS UUID) "; filterParams.add(astroType); } */ /* if (aroundAstroUid && aroundAstroUid != "") { filterWhere = " AND around.uid = CAST(? AS UUID) "; filterParams.add(aroundAstroUid); } _log.info("Filter params:", filterParams); */ const dbAstros = _db.query(` SELECT astro.uid --astro.id, ,astro.name ,astro_type.name AS "astro_type" --,astro_type.id AS "astro_type_code" --astro.equatorial_radius, --astro.rotation_velocity, --,astro.around_astro_id --,around.uid as "around_astro_uid" ,astro.periapsis ,astro.apoapsis --astro.image FROM astro INNER JOIN astro_type ON astro.type_id = astro_type.id LEFT JOIN ( SELECT id,uid,name FROM astro ) AS around ON astro.around_astro_id = around.id WHERE astro.active = TRUE AND astro_type.active = TRUE AND around.uid = ?::uuid `,aroundAstroUid); /* ${filterWhere} --LIMIT 8 --OFFSET ${offset} `, filterParams); */ const astros = _val.list() for (const dbAstro of dbAstros) { astros.add( _val.map() .set('id', dbAstro.getString('uid')) .set('name', dbAstro.getString('name')) .set('type', dbAstro.getString('astro_type')) .set('periapsis', dbAstro.getString('periapsis')) .set('apoapsis', dbAstro.getString('apoapsis')) ) } // DEBUG...COMENTAR DEPOIS! //_log.info( 'Server return...', astros ); _out.json(astros); // DEBUG...COMENTAR DEPOIS! _log.info('service ended!');