sql – why the row entry is not shown in mysql table but being fetched in api but after sometime it deleted from every place?

I am inserting a row in a mysql table , it is successfully inserted as it is fetched in get api but not showing in that database table. If I insert a new row again then the previous one suddenly shown but the new one not. If I don’t insert any row again , after sometime the row will not be fetched in api also like it is deleted from everywhere.

I think this is something related to autocommit or have_query_cache but I don’t know how to solve this.

Notification.sendNotification = function (postData, result) {
    // save in db
    var insertData = {
        user_id: postData.user_id ? postData.user_id : 0,
        refer_user_id: postData.refer_user_id ? postData.refer_user_id : 0,
        wallet_txn_id: postData.walletTxnId ? postData.walletTxnId : '',
        account_id: postData.account_id ? postData.account_id : '',
        user_account_id: postData.user_account_id ? postData.user_account_id : '',
        raise_request_id: postData.raise_request_id ? postData.raise_request_id : '',
        title: postData.title ? postData.title : '',
        remark: postData.remark ? postData.remark : '',
        remark_text: postData.remark_text ? postData.remark_text : postData.remark,
        type: postData.type ? postData.type : '',
        txn_type: postData.txn_type ? postData.txn_type : '',
        notification_type: postData.notification_type ? postData.notification_type : '',
        redirect: postData.redirect ? postData.redirect : '',
        route: postData.route ? postData.route : '',
        status: 0,
        created_on: new Date(),
        image: postData.image
    }
    
    // console.log('postData', postData);
    
    db.query("INSERT INTO user_notification set ?", insertData, function (err, res) {
        if (err) {
            console.log("error: ", err);
            result(err, null);
        }
        else {
            var notification_id = res.insertId;
            console.log('notification_id', notification_id);
            var queryString = "SELECT fcm_token FROM users WHERE id = ?;"
            var filter = [postData.user_id];
            db.query(queryString, filter, function (err, res) {
                if (err) {
                    console.log("error: ", err);
                    result(err, null);
                }
                else {
                    var Tokens = [];
                    if (res.length) {
                        res.forEach(element => {
                            if (element.fcm_token) {
                                Tokens.push(element.fcm_token);
                            }
                        });
                        
                        if (!Tokens.length) {
                            result(null, res);
                        }
                        
                        var message = {
                            registration_ids: Tokens,
                            
                            notification: {
                                title: postData.title,
                                body: postData.remark_text ? postData.remark_text : postData.remark,
                                image: postData.image,
                            },
                            
                            data: {  //you can send only notification or only data(or include both)
                                wallet_txn_id: postData.walletTxnId ? postData.walletTxnId.toString() : '',
                                raise_request_id: postData.raise_request_id ? postData.raise_request_id.toString() : '',
                                notification_id: notification_id.toString(),
                                notification_type: postData.notification_type ? postData.notification_type : '',
                                redirect: postData.redirect ? postData.redirect.toString() : '',
                                route: postData.route ? postData.route.toString() : '',
                            },
                            android: {
                                notification: {
                                    sound: 'default',
                                    click_action: "FCM_PLUGIN_ACTIVITY",
                                },
                            },
                        };
                        
                        if (postData.package_name == 'com.allpunt.wallet') {
                            
                            fcmAllPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                    result(err, null);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.starpunt.wallet') {
                            fcmStarPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.jetpunt.wallet') {
                            fcmJetPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        }
                        else if (postData.package_name == 'com.lordpunt.wallet') {
                            fcmLordPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.kingpunt.wallet') {
                            fcmKingPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.ganeshpunt.wallet') {
                            fcmGaneshPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.mahadevpunt.wallet') {
                            fcmMahaDevPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.punt777.wallet') {
                            fcm777Punt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        }
                        else if (postData.package_name == 'com.copunt.wallet') {
                            fcmCOPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        }
                        else if (postData.package_name == 'com.betpunt.wallet') {
                            fcmBetPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        }
                        else if (postData.package_name == 'com.fairpunt.wallet') {
                            fcmFairPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.sprinterspunt.wallet') {
                            fcmSprintersPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.sdpunt.wallet') {
                            fcmSDPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.dspunt.wallet') {
                            fcmDSPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.sairampunt.wallet') {
                            fcmSaiRamPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        }
                        else if (postData.package_name == 'com.indiapunt.wallet') {
                            fcmIndiaPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.balajipunt.wallet') {
                            fcmBalajiPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.acepunt.wallet') {
                            fcmAcePunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.ferraripunt.wallet') {
                            fcmFerrariPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        }
                        else if (postData.package_name == 'com.teslapunt.wallet') {
                            fcmTeslaPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        }
                        else if (postData.package_name == 'com.propunt.wallet') {
                            fcmProPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        }else if (postData.package_name == 'com.skypunt.wallet') {
                            fcmSkyPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.gopanel.wallet') {
                            fcmGoPanel.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.prtpunt.wallet') {
                            fcmPrtPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.dubaipunt.wallet') {
                            fcmDubaiPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.vlpunt.wallet') {
                            fcmViPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.vippunt.wallet') {
                            fcmVipPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.safepunt.wallet') {
                            fcmSafePunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.sportspunt.wallet') {
                            fcmSportsPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        }else if (postData.package_name == 'com.matchpunt.wallet') {
                            fcmMatchPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        }else if (postData.package_name == 'com.playpunt.wallet') {
                            fcmPlayPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else if (postData.package_name == 'com.wildpunt.wallet') {
                            fcmWildPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                            
                        } else {
                            fcmGoPunt.send(message, function (err, response) {
                                if (err) {
                                    // console.log(JSON.parse(err));
                                    console.log("Something has gone wrong!", err);
                                } else {
                                    console.log("Successfully sent with response: ", response);
                                }
                                
                                result(null, response);
                            });
                        }
                    }
                }
            });
        }
    });
};

Leave a Comment