utils.js 678 B

123456789101112131415161718192021222324252627282930313233343536
  1. const {
  2. userCollection
  3. } = require('../../common/constants')
  4. const {
  5. ERROR
  6. } = require('../../common/error')
  7. const {
  8. findUser
  9. } = require('../../lib/utils/account')
  10. async function isAuthorizeApproved ({
  11. uid,
  12. appIdList
  13. } = {}) {
  14. const getUserRes = await userCollection.doc(uid).get()
  15. const userRecord = getUserRes.data[0]
  16. if (!userRecord) {
  17. throw {
  18. errCode: ERROR.ACCOUNT_NOT_EXISTS
  19. }
  20. }
  21. const userMatched = await findUser({
  22. userQuery: userRecord,
  23. authorizedApp: appIdList
  24. })
  25. if (userMatched.some(item => item._id !== uid)) {
  26. throw {
  27. errCode: ERROR.ACCOUNT_CONFLICT
  28. }
  29. }
  30. }
  31. module.exports = {
  32. isAuthorizeApproved
  33. }