/**
* @description shop router
*/
const router = require('koa-router')()
const {
getHotList,
getShopInfo,
getProductsByShopId
} = require('../controller/shop')
const { SuccessModel, ErrorMOdel } = require('../res-model/index')
router.prefix('/api/shop')
//附近所有(热门)商店
router.get('/hot-list', async (ctx, next) => {
const list = await getHotList()
ctx.body = new SuccessModel(list)
})
//附近(某个)商店详情
router.get('/:id', async (ctx, next) => {
const id = ctx.params.id
const shop = await getShopInfo(id)
ctx.body = new SuccessModel(shop)
})
//查询(某个)商店的商品列表
router.get('/:id/products', async (ctx, next) => {
const shopId = ctx.params.id
const tab = ctx.query.tab || 'all'
const products = await getProductsByShopId(shopId, tab)
ctx.body = new SuccessModel(products)
})
// 获取热词列表
router.get('/search/hot-words', async (ctx, next) => {
const list = ['番茄', '苹果', '葡萄']
ctx.body = new SuccessModel(list)
})
//获取搜索页列表
router.get('/search', async (ctx, next) => {
// const shopList=await getHotList()
const list = ['番茄', '苹果', '葡萄']
ctx.body = new SuccessModel(list)
})
module.exports = router
只有最后一个路由不能用
Error
Looks like something broke!
CastError: Cast to ObjectId failed for value "search" (type string) at path "_id" for model "shop"
at model.Query.exec (C:\Users\jh\Desktop\test\xiaomujishi-server\node_modules\mongoose\lib\query.js:4884:21)
at model.Query.Query.then (C:\Users\jh\Desktop\test\xiaomujishi-server\node_modules\mongoose\lib\query.js:4983:15)
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星