{"size": 1273, "ext": "js", "max_stars_repo_path": "src/feature/Chatible/userSendRequest.js", "max_stars_repo_name": "aldermann/chatcouple", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/feature/Chatible/userSendRequest.js", "max_issues_repo_name": "aldermann/chatcouple", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/feature/Chatible/userSendRequest.js", "max_forks_repo_name": "aldermann/chatcouple", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.0487804878, "max_line_length": 61, "alphanum_fraction": 0.3032207384}
import mongodb from 'mongodb';
import cache from 'memory-cache';
const MongoClient = mongodb.MongoClient;

export default (senderId, timestamp) => {
    return new Promise(resolve => {
        MongoClient.connect(
            process.env.MONGODB_URI,
            {
                useNewUrlParser: true
            },
            (err, db) => {
                if (err) throw err;
                db.db(
                    process.env.MONGODB_NAME ||
                        process.env.MONGODB_URI.split('/')[3]
                )
                    .collection('users')
                    .updateOne(
                        {
                            _id: senderId
                        },
                        {
                            $set: {
                                status: 1,
                                timestamp: timestamp
                            }
                        },
                        (err, obj) => {
                            if (err) throw err;
                            db.close(null, () => {
                                cache.put(senderId, 1);
                                resolve(obj);
                            });
                        }
                    );
            }
        );
    });
};
