category.js 702 B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. import CategoryModel from '../../models/shopping/category'
  3. import BaseComponent from '../../prototype/baseComponent'
  4. class Category extends BaseComponent{
  5. constructor(){
  6. super()
  7. }
  8. //获取所有餐馆分类和数量
  9. async getCategories(req, res, next){
  10. try{
  11. const categories = await CategoryModel.find({}, '-_id');
  12. res.send(categories);
  13. }catch(err){
  14. console.log('获取categories失败');
  15. res.send({
  16. status: 0,
  17. type: 'ERROR_DATA',
  18. message: '获取categories失败'
  19. })
  20. }
  21. }
  22. async addCategory(type){
  23. try{
  24. await CategoryModel.addCategory(type)
  25. }catch(err){
  26. console.log('增加category数量失败');
  27. }
  28. }
  29. }
  30. export default new Category()