readNoticeService.js 688 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. const Service = require('../service/baseService');
  3. class ReadNoticeService extends Service {
  4. tag() {
  5. return this.ctx.model.ReadNoticeModel;
  6. }
  7. async add(data) {
  8. const { model } = this.ctx;
  9. const result = await model.ReadNoticeModel.create(data);
  10. return result;
  11. }
  12. async appList(data) {
  13. const { model } = this.ctx;
  14. const match = {};
  15. match._id = data.userid;
  16. const result = await model.ReadNoticeModel.aggregate([{ $group: { _id: '$userid', noticeId: { $addToSet: '$noticeId' } } }, { $match: match }]);
  17. if (result.length > 0) {
  18. return result[0].noticeId;
  19. }
  20. return [];
  21. }
  22. }
  23. module.exports = ReadNoticeService;