Notify.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * Created by Administrator on 2015/4/15.
  3. * 文章标签对象
  4. */
  5. var mongoose = require('mongoose');
  6. var shortid = require('shortid');
  7. var Schema = mongoose.Schema;
  8. var User = require('./User');
  9. var AdminUser = require('./AdminUser');
  10. var Content = require('./Content');
  11. var NotifySchema = new Schema({
  12. _id: {
  13. type: String,
  14. unique: true,
  15. 'default': shortid.generate
  16. },
  17. title : {type: String }, // 消息的标题
  18. content : {type: String }, // 消息的内容
  19. type : {type: String , enum: ['1', '2', '3']}, // 消息的类型,1: 公告 Announce,2: 提醒 Remind,3:信息 Message
  20. target : {type: String , ref : 'Content' }, // 目标的ID
  21. targetType : {type: String }, // 目标的类型
  22. action : {type: String }, // 提醒信息的动作类型
  23. sender : {type: String , ref : 'User'}, // 发送者的ID
  24. adminSender : {type: String , ref : 'AdminUser'}, // 发送者的ID
  25. systemSender : {type: String }, // 系统消息发送者
  26. date : { type: Date, default: Date.now }
  27. });
  28. NotifySchema.statics = {
  29. delOneNotify : function(res,notifyId,callBack){
  30. if(shortid.isValid(notifyId)){
  31. Notify.remove({'_id' : notifyId},function(err,result){
  32. if(err){
  33. res.end(err);
  34. }else{
  35. callBack();
  36. }
  37. })
  38. }else{
  39. res.end('参数非法');
  40. }
  41. },
  42. //发送系统消息给管理后台
  43. sendSystemNotice : function(res,noticeObj,callBack){
  44. var notify = new Notify(noticeObj);
  45. notify.save(function(err){
  46. if(err){
  47. res.end(err);
  48. }else{
  49. AdminUser.find({},'_id',function (err,users) {
  50. if(err){
  51. res.end(err);
  52. }else{
  53. callBack(users,notify);
  54. }
  55. });
  56. }
  57. });
  58. }
  59. };
  60. var Notify = mongoose.model("Notify",NotifySchema);
  61. module.exports = Notify;