index.js 857 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // 云函数入口文件
  2. const cloud = require('wx-server-sdk')
  3. cloud.init()
  4. const db = cloud.database()
  5. // 云函数入口函数
  6. exports.main = async (event, context) => {
  7. const {
  8. OPENID
  9. } = cloud.getWXContext()
  10. const notifications = await db.collection('notification')
  11. .aggregate()
  12. .match({
  13. user_id: OPENID
  14. })
  15. .skip(event.page_token)
  16. .limit(event.page_size)
  17. .lookup({
  18. from: 'message',
  19. localField: 'msg_id',
  20. foreignField: '_id',
  21. as: 'message'
  22. })
  23. .unwind('$message')
  24. .lookup({
  25. from: 'publisher',
  26. localField: 'message.pub_id',
  27. foreignField: '_id',
  28. as: 'message.publisher'
  29. })
  30. .unwind('$message.publisher')
  31. .end()
  32. return {
  33. list: notifications.list,
  34. next_page_token: event.page_token + notifications.list.length,
  35. status: 'OK'
  36. }
  37. }