From eabf5b9f6c21cc31c6b3b727462cc730224e27dc Mon Sep 17 00:00:00 2001 From: mohammed medhat Date: Sun, 24 Sep 2023 20:13:07 +0300 Subject: [PATCH] Refactoring matching feature 0.9 --- src/utils/sockets.js | 133 ------------------------------------------- 1 file changed, 133 deletions(-) diff --git a/src/utils/sockets.js b/src/utils/sockets.js index b1e26f6..9fb83f3 100644 --- a/src/utils/sockets.js +++ b/src/utils/sockets.js @@ -1,6 +1,3 @@ -const User = require('../models/user.model'); -// const { createClient } = require('redis'); -// const dyte = require('./dyte'); const { findMatch, clinetApproval, @@ -8,136 +5,6 @@ const { clientCancelation } = require('./../services/matching.services'); -// const redisConfig = -// process.env.NODE_ENV === 'production' -// ? { -// url: process.env.REDIS_URL -// } -// : {}; - -// const redisClient = createClient(redisConfig); - -// redisClient.on('error', err => console.log('Redis Client Error', err)); - -// (async function connect() { -// await redisClient.connect(); -// })(); - -// async function setOne(key, value) { -// await redisClient.set(key, value); -// } - -// async function setMany(keys, value) { -// console.log('hi from set many'); -// console.log(keys, value); -// // await Promise.all( -// keys.forEach(async key => { -// // The key you want to check for - -// // Use the EXISTS command to check if the key exists -// console.log(key); -// redisClient.sAdd(key, value, (err, addedCount) => { -// if (err) { -// console.error('Error adding values to set:', err); -// return; -// } -// console.log('Added', key, value, 'to set', addedCount, 'times'); -// }); -// // if ((await redisClient.get(keyToCheck)) === null) { -// // console.log('key does not exist', key, value); -// // await redisClient.sAdd(key, value, (err, reply) => { -// // if (err) { -// // console.error('Error setting key:', err); -// // return; -// // } -// // console.log('Key set successfully:', reply); -// // }); -// // } else { -// // //test -// // console.log('key exists', key, value); -// // redisClient.sAdd(key, 'fifdas', (err, addedCount) => { -// // if (err) { -// // console.error('Error adding values to set:', err); -// // return; -// // } -// // console.log('Added', key, value, 'to set', addedCount, 'times'); -// // }); -// // } -// }); -// } - -// function getcrossSkill(str) { -// return `${str.split('/')[1]}/${str.split('/')[0]}`; -// } - -// async function searchForMatch(crossSkill, notToProvide) { -// return new Promise(resolve => { -// let results = {}; -// //set interval for firing the search every 1/2 secend -// const intervalId = setInterval(async () => { -// console.log('searching for match'); -// const crossSkillUsers = await getMany(crossSkill); -// //remove any user that is in notToProvide -// console.log( -// crossSkillUsers, -// 'crossSkill', -// notToProvide, -// 'notToProvide' -// ); -// crossSkillUsers.filter(user => { -// if (!notToProvide.includes(user)) { -// console.log('user not in notToProvide', user); -// return user; -// } -// }); - -// console.log(crossSkillUsers, notToProvide); -// if (crossSkillUsers.length > 0) { -// results = { found: true, MatchedUserId: crossSkillUsers[0] }; -// console.log('match found', results); -// } else { -// results = { found: false, MatchedUserId: null }; -// console.log('no match found', results); -// } -// }, 1 * 1000); - -// //set time out for searching for match 5 secends (if no match found) -// setTimeout(() => { -// console.log('returning results', results); -// clearInterval(intervalId); -// resolve(results); -// }, 5 * 1000); -// }); -// } - -// function createSkills(wantedSkill, userSkills) { -// const userSkillsArray = [...new Set(userSkills)]; -// let strings = []; -// console.log(userSkillsArray, wantedSkill); -// userSkillsArray.map(skill => { -// strings.push(`${skill}/${wantedSkill}`); -// }); -// return strings; -// } - -// async function getOne(key) { -// return await redisClient.get(key); -// } - -// async function removeFromSet(key, value) { -// await redisClient.sRem(key, value, (err, reply) => { -// if (err) { -// console.error('Error removing value from set:', err); -// return; -// } -// console.log('Removed', value, 'from set', key, reply, 'times'); -// }); -// } - -// async function getMany(key) { -// return await redisClient.sMembers(key); -// } - const listen = function(io) { console.log( `Socket server start listening on server port ${process.env.PORT}`