utils.js 688 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 {
  22. userMatched
  23. } = await findUser({
  24. userQuery: userRecord,
  25. authorizedApp: appIdList
  26. })
  27. if (userMatched.some(item => item._id !== uid)) {
  28. throw {
  29. errCode: ERROR.ACCOUNT_CONFLICT
  30. }
  31. }
  32. }
  33. module.exports = {
  34. isAuthorizeApproved
  35. }