0

I am creating a class in JavaScript, in that class I created a few functions however only the constructor seems to work. What am I missing because I did another class in the same exact format and it worked perfectly.

class Articles {
    constructor(dbName = ':memory:') {
        return // Some async function  
            return this
        })()
    }
    async all() {
        //another async function
        }
        return articles
    }
    async add(data) {
        console.log('ADD')
        console.log(data)
        return true
    }
    async close() {
        await this.db.close
    }
}
export default Articles

I have taken out the parts that I dont think are necessary just so that its easier to read. The issue I have is with the last two functions add and close. The class exports fine. This is the type error that I keep getting

Here is the function that I run it in

router.post('/add', async ctx => {
    const a = await new Articles(dbName)
    try{
        ctx.request.body.account = ctx.session.userid
        }
        await new Articles(dbName).add(ctx.request.body) //Here is the add function
        return ctx.redirect('/?msg=new article added')
    } catch(err) {
        console.log(err)
        await ctx.render('error', ctx.hbs)
    } finally {
        new Articles(dbName).close() //Here is the close function
    }
})

0 Answers0