From 9e0271bd98c74369fcdfebc1a7bc6551fc2cd72c Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Tue, 23 Jun 2020 19:12:01 -0400 Subject: [PATCH] delete merge artifact --- services/gunDB/contact-api/getters.js | 105 -------------------------- 1 file changed, 105 deletions(-) delete mode 100644 services/gunDB/contact-api/getters.js diff --git a/services/gunDB/contact-api/getters.js b/services/gunDB/contact-api/getters.js deleted file mode 100644 index 0fcf9805..00000000 --- a/services/gunDB/contact-api/getters.js +++ /dev/null @@ -1,105 +0,0 @@ -/** - * @format - */ -const Common = require('shock-common') -const Logger = require('winston') - -const Key = require('./key') -const Utils = require('./utils') - -/** - * @param {string} pub - * @returns {Promise} - */ -exports.currentOrderAddress = async pub => { - const currAddr = await Utils.tryAndWait(gun => - gun - .user(pub) - .get(Key.CURRENT_ORDER_ADDRESS) - .then() - ) - - if (typeof currAddr !== 'string') { - throw new TypeError('Expected user.currentOrderAddress to be an string') - } - - return currAddr -} - -/** - * @param {string} pub - * @returns {Promise} - */ -exports.userToIncomingID = async pub => { - const incomingID = await require('../Mediator') - .getUser() - .get(Key.USER_TO_INCOMING) - .get(pub) - .then() - - if (typeof incomingID === 'string') return incomingID - - return null -} - -/** - * @param {string} publicKey - * @returns {Promise} - */ -const getUser = async publicKey => { - /** - * @type {Common.Schema.User} - */ - const user = { - avatar: null, - bio: null, - displayName: null, - lastSeenApp: 0, - lastSeenNode: 0, - publicKey - } - - /** - * @type {unknown} - */ - const profile = await Utils.tryAndWait( - gun => - new Promise(res => { - const userNode = gun.get(`~${publicKey}`) - - userNode.load(data => res(data)) - }), - v => typeof v === 'object' && v !== null - ) - - if ( - typeof profile === 'object' && - profile !== null && - Common.Schema.isUser({ - ...profile, - publicKey - }) - ) { - Object.assign(user, profile) - Logger.error( - `Invalid profile found for publicKey: ${publicKey}, found: ${JSON.stringify( - profile - )}` - ) - } - - return user -} - -exports.getUser = getUser - -exports.getMyUser = () => { - const user = require('../Mediator').getUser() - const publicKey = user.is && user.is.pub - - if (typeof publicKey !== 'string') { - throw new Error('NOT_AUTH') - } - - return getUser(publicKey) -}