search.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. import BaseComponent from '../../prototype/baseComponent';
  3. import Cities from '../../models/v1/cities';
  4. class SearchPlace extends BaseComponent{
  5. constructor(){
  6. super()
  7. }
  8. async search(req, res, next){
  9. const {type, city_id, keyword} = req.query;
  10. if (!type || isNaN(city_id) || !keyword) {
  11. res.send({
  12. name: 'ERROR_QUERY_TYPE',
  13. message: '参数错误',
  14. })
  15. return
  16. }
  17. try{
  18. const cityInfo = await Cities.getCityById(city_id);
  19. const aaa = await this.fetch('http://restapi.amap.com/v3/place/text?key=e1467cff48d3359df43012aa8c3a252b&keywords=北京大学&types=141201&city=北京&children=1&offset=20&page=1&extensions=all')
  20. // const resList = await this.fetch(http://restapi.amap.com/v3/place/text', {
  21. // key: 'e1467cff48d3359df43012aa8c3a252b',
  22. // keywords: keyword,
  23. // types: 141201,
  24. // city: cityInfo.name,
  25. // children: 1,
  26. // offset: 10,
  27. // page: 1,
  28. // extensions: 'all',
  29. // })
  30. res.send(aaa);
  31. }catch(err){
  32. res.send(err);
  33. }
  34. }
  35. }
  36. export default new SearchPlace();