Source

lib/inventory/getUAIDs.js

  1. // Includes
  2. const getCollectibles = require('./getCollectibles.js').func
  3. // Args
  4. exports.required = ['userId', 'assetIds']
  5. exports.optional = ['exclusionList', 'jar']
  6. // Docs
  7. /**
  8. * ✅ Get a UserAssetID for a specific asset.
  9. * @category User
  10. * @alias getUAIDs
  11. * @param {number} userId - The id of the user to search.
  12. * @param {Array<number>} assetIds - The ids of the assets to retrieve.
  13. * @param {Array<number>=} exclusionList - The UAIDs to exclude from the search.
  14. * @returns {Promise<UAIDResponse>}
  15. * @example const noblox = require("noblox.js")
  16. * const UAIDInfo = await noblox.getUAIDs(80231025, [1974901902, 4255053867, 2705893733, 1532395])
  17. **/
  18. // Define
  19. function getUAIDs (userId, requestedIds, excludedIds) {
  20. return new Promise((resolve) => {
  21. getCollectibles({ userId }).then(function (collectibles) {
  22. const retrievedIds = []
  23. for (let index = 0; index < collectibles.length; index++) {
  24. const collectible = collectibles[index]
  25. const requestIndex = requestedIds.indexOf(collectible.assetId)
  26. if (requestIndex > -1 && excludedIds.indexOf(collectible.userAssetId) === -1) {
  27. requestedIds.splice(requestIndex, 1)
  28. retrievedIds.push(collectible.userAssetId)
  29. }
  30. }
  31. resolve({
  32. uaids: retrievedIds,
  33. failedIds: requestedIds
  34. })
  35. })
  36. })
  37. }
  38. exports.func = function (args) {
  39. return getUAIDs(args.userId, args.assetIds, args.exclusionList || [])
  40. }