From 7128822359a977fa778408bfc4b72b2e18f06772 Mon Sep 17 00:00:00 2001 From: himaniraghav3 Date: Mon, 19 Jan 2026 17:29:41 +0530 Subject: [PATCH] PM-2394 cleanup looker based member verification --- config/default.js | 2 - src/common/LookerApi.js | 12 -- .../IdVerificationProcessorService.js | 143 ------------------ 3 files changed, 157 deletions(-) delete mode 100644 src/services/IdVerificationProcessorService.js diff --git a/config/default.js b/config/default.js index b77204d..b6d9982 100644 --- a/config/default.js +++ b/config/default.js @@ -69,8 +69,6 @@ module.exports = { }, ID_VERIFICATION_PROCESSOR_CRON_EXPRESSION: process.env.ID_VERIFICATION_PROCESSOR_CRON_EXPRESSION || '0 */12 * * *', - PAUSE_ID_VERIFICATION: process.env.PAUSE_ID_VERIFICATION || false, - FETCH_LOOKER_VERIFIED_MEMBER_TIMEFRAME_DAYS: process.env.FETCH_LOOKER_VERIFIED_MEMBER_TIMEFRAME_DAYS || '3', // looker-api config lookerConfig: { BASE_URL: process.env.LOOKER_API_BASE_URL || '', // looker api base url diff --git a/src/common/LookerApi.js b/src/common/LookerApi.js index 1890922..8beae56 100644 --- a/src/common/LookerApi.js +++ b/src/common/LookerApi.js @@ -20,18 +20,6 @@ function LookApi (logger) { this.lookAuth = new LookAuth(logger) } -/** - * Find recent verified members - * @param {String} duration the verification date duration to filter - * @returns an array of verified members - */ -LookApi.prototype.findRecentVerifiedMembers = function (duration) { - const view = 'member_verification' - const fields = ['member_verification.user_id', 'member_verification.verification_mode', 'member_verification.status', 'member_verification.matched_on', 'member_verification.verification_date'] - const filters = { 'member_verification.verification_date': duration } - return this.runQueryWithFilter('member_profile', view, fields, filters) -} - /** * Run query with filter * @param {String} model the model name diff --git a/src/services/IdVerificationProcessorService.js b/src/services/IdVerificationProcessorService.js deleted file mode 100644 index e17b67c..0000000 --- a/src/services/IdVerificationProcessorService.js +++ /dev/null @@ -1,143 +0,0 @@ -/** - * This service handles the id verification - */ - -const _ = require('lodash') -const logger = require('../common/logger') -const helper = require('../common/helper') -const LookerApi = require('../common/LookerApi') -const constants = require('../common/constants') -const config = require('config') -const { ID_VERIFICATION_PROPERTY_NAME } = require('../common/constants') - -/** - * This is the main function of the processor which handles saving the id verification as member traits - */ -async function processIdVerification () { - if (config.PAUSE_ID_VERIFICATION && _.toLower(config.PAUSE_ID_VERIFICATION) === 'true') { - logger.info('The id verification is currently paused') - return - } - logger.info({ - component: 'IdVerificationProcessorService', - context: 'processIdVerification', - message: 'Processing id verification' - }) - - const idVerifications = [] - try { - const api = new LookerApi(logger) - // Get the modified id verification records in the last X (configurable) days - const resp = await api.findRecentVerifiedMembers(`last ${config.FETCH_LOOKER_VERIFIED_MEMBER_TIMEFRAME_DAYS} days`) - - // Transfer the key name from member_verification.** to ** and filter the status isn't verified - idVerifications.push(..._.filter(_.map(resp, o => _.mapKeys(o, (v, k) => _.replace(k, 'member_verification.', ''))), ['status', 'Verified'])) - - logger.info({ - component: 'IdVerificationProcessorService', - context: 'processIdVerification', - message: `Successfully queued id verification for ${idVerifications.length} verifications fetched from looker` - }) - } catch (e) { - logger.error({ - component: 'IdVerificationProcessorService', - context: 'processIdVerification', - message: `An error occurred when fetching id verification, error = ${e.message}` - }) - throw e - } - // Save the id verification as member traits - for (const idVerification of idVerifications) { - try { - await saveIdVerificationTrait(idVerification) - } catch (err) { - logger.error({ - component: 'IdVerificationProcessorService', - context: 'processIdVerification', - message: `An error occurred when saving id verification, error = ${err.message}` - }) - } - } -} - -/** - * This function saved the provided id verification as member traits - * - * @param {Object} idVerification The id verification to set as member trait - */ -async function saveIdVerificationTrait (idVerification) { - // Get the user handle from members api - const handle = await helper.getHandleByUserId(_.get(idVerification, 'user_id')) - - logger.debug({ - component: 'IdVerificationProcessorService', - context: 'saveIdVerificationTrait', - message: `Saving id verification member trait for user '${handle}'` - }) - - // Get the member Onboarding Checklist traits - const onboardingChecklistTraits = await helper.getMemberTraits(handle, constants.ONBOARDING_CHECKLIST_TRAIT_ID) - - // construct the request body for saving the member traits - const body = [{ - categoryName: constants.ONBOARDING_CHECKLIST_CATEGORY_NAME, - traitId: constants.ONBOARDING_CHECKLIST_TRAIT_ID, - traits: { - traitId: constants.ONBOARDING_CHECKLIST_TRAIT_ID, - data: [] - } - }] - - // Initialize the id verification traits data object - const traitsData = { - status: constants.CHECKLIST_STATUS.COMPLETED, - message: constants.CHECKLIST_MESSAGE.SUCCESS, - date: new Date(idVerification.verification_date).getTime(), - metadata: { - matched_on: idVerification.matched_on, - verification_mode: idVerification.verification_mode - } - } - - if (onboardingChecklistTraits.length === 0) { - // Onboarding checklist traits does not exist for the member, we need to create it - body[0].traits.data.push({ - [ID_VERIFICATION_PROPERTY_NAME]: traitsData - }) - await helper.saveMemberTraits(handle, body, true) - } else { - // Onboarding checklist traits already exists for the member - // Check if the id verification was updated - const idVerificationEqualityCheckFields = ['status', 'message', 'date', 'metadata.matched_on', 'metadata.verification_mode'] - if (!_.isUndefined(onboardingChecklistTraits[0].traits.data[0][ID_VERIFICATION_PROPERTY_NAME]) && - _.isEqual(_.pick(traitsData, idVerificationEqualityCheckFields), - _.pick(onboardingChecklistTraits[0].traits.data[0][ID_VERIFICATION_PROPERTY_NAME], idVerificationEqualityCheckFields))) { - // the id verification trait is already set in traits api, no need to re-update - logger.debug( - { - component: 'IdVerificationProcessorService', - context: 'saveIdVerificationTrait', - message: `Id verification trait is already set for user '${handle}', Skipping...!` - }) - return - } else { - // Copy the existing traits data to the request body - body[0].traits.data[0] = _.cloneDeep(onboardingChecklistTraits[0].traits.data[0]) - - // Add the currently processed id verification to the request body - body[0].traits.data[0][ID_VERIFICATION_PROPERTY_NAME] = traitsData - await helper.saveMemberTraits(handle, body, false) - } - } - logger.debug({ - component: 'IdVerificationProcessorService', - context: 'saveIdVerificationTrait', - message: `Successfully completed saving id verification member trait for user '${handle}'` - }) -} - -module.exports = { - processIdVerification -} - -logger.buildService(module.exports, 'IdVerificationProcessorService')