cool 中的node.js 实现一个处理第三方Api 数据的处理

1.需求

你现在是一个后端 前端跟你要一个接口 ,但是你发现 你这个接口 除了调用第三方Api的接口 有的数据还是没有 你直接返回 前端使用不了 因为都没有关于那样的数据 但是三方Api 中有其他的接口和现在的接口 经过处理 是可以实现这个前端需要的数据。遇到这样的情况 cool Node.js框架,其实是和Java 中的sping boot是相似的。都是由controller 和 service

我认为所有的后端框架 目前都类似 只要不是写基础的代码 基本的逻辑都一样

java php cool go 在现在现代框架的基础上 框架的基本逻辑都一样 写法不一样而已

2.实现

controller代码

现在你看到的是一个接口 我的post 是封装了一个 方法 所以调用直接就相当于发起了post请求 向三方Api 经过处理这样可以获取到数据

肯定我的代码你们不能使用 但是我是想告诉你们基本的逻辑 在三方API 没有对应的接口的情况下 我们只能暂时这样处理

复制代码
  @Get('/FilmDate', { summary: '获取这个影片在城市下的所有有排期的日期数组' })
  async FilmDateList(@Query() query) {
    const url = '/api/xxx/xxx/cinemaShowList';
    const cinemaListUrl = '/api/xxx/xxx/cinemaList';
    try {
      let cinemaInfo = {
        currentPage: 1,
        pageSize: 99,
        filmId: query.filmId,
        areaId: query.areaCode,
      };
      const allCinemaList = await this.mangoRequestService.post(
        cinemaListUrl,
        cinemaInfo
      );
      if (!allCinemaList.list.length) {
        return this.ok([]);
      }
      const aggrementList = await this.mangoRequestService.post(url, {
        filmId: query.filmId,
        cinemaId: allCinemaList.list[0].id,
      });
      let date = [];
      aggrementList?.forEach(item => {
        if (item.showDate) {
          date.push(item.showDate);
        }
      });

      return this.ok([...new Set(date)]);

      // const MovieList = await this.getList(query);
      // console.log(MovieList, 'MovieList');
    } catch (error) {
      throw new CoolCommException(error.message);
    }
  }
相关推荐
smallzip2 小时前
node大文件拷贝优化(显示进度)
前端·性能优化·node.js
蓝胖子的多啦A梦4 小时前
npm : 无法加载文件 C:\Program Files\nodejs\npm.ps1,因为在此系统上禁止运行脚
前端·npm·node.js
Spider_Man4 小时前
“AI查用户”也能这么简单?手把手带你用Node.js+前端玩转DeepSeek!
javascript·人工智能·node.js
龚思凯7 小时前
Node.js 模块导入语法变革全解析
后端·node.js
冷凌爱8 小时前
Fetch与Axios:区别、联系、优缺点及使用差异
前端·node.js·js
Sailing8 小时前
Grafana-mcp-analyzer:基于 MCP 的轻量 AI 分析监控图表的运维神器!
前端·node.js·mcp
XI锐真的烦9 小时前
横向对比npm和yarn
前端·npm·node.js
穗余10 小时前
WEB3全栈开发——面试专业技能点P1Node.js / Web3.js / Ethers.js
javascript·node.js·web3
贩卖纯净水.1 天前
Webpack的基本使用 - babel
前端·webpack·node.js
贩卖纯净水.1 天前
Webpack依赖
前端·webpack·node.js