src/database/client.js
/**
 * Connect to the database or validate the connection status
 * @returns {Promise<void>}
 */
Connect to the database or validate the connection status
@returns {Promise}
Connect to the database or validate the connection status @returns { Promise }
async function prepareConnection() {
    return new Promise((resolve, reject) => {
        if (global.databaseConnected !== true) {
            connect(process.env.DATABASE_URL)
                .then((db) => {
                    global.databaseConnected = true
                    db.connection.once("error", (err) => {
                        console.error("Mongoose error:", err)
                        setTimeout(async () => {
                            console.warn("Trying to reconnect...")
                            await prepareConnection()
                            resolve()
                        }, 5000)
                    })
                    resolve()
                })
                .catch((...err) => reject(...err))
        } else {
            resolve()
        }
    })
}
async function prepareConnection ( ) { return new Promise ( ( resolve , reject ) => { if ( global . databaseConnected !== true ) { connect ( process . env . DATABASE_URL ) . then ( ( db ) => { global . databaseConnected = true db . connection . once ( "error" , ( err ) => { console . error ( "Mongoose error:" , err ) setTimeout ( async ( ) => { console . warn ( "Trying to reconnect..." ) await prepareConnection ( ) resolve ( ) } , 5000 ) } ) resolve ( ) } ) . catch ( ( ... err ) => reject ( ... err ) ) } else { resolve ( ) } } ) }
Connect to the database or validate the connection status
 @returns {Promise<void>}
Connect to the database or validate the connection status @returns { Promise<void > }
// eslint-disable-next-line prefer-promise-reject-errors