Skip to content
Permalink
ef5484962f
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
49 lines (40 sloc) 1.46 KB
const sqlite = require('sqlite-async')
module.exports = class List {
constructor(dbName = ':memory:') {
return (async() => {
this.db = await sqlite.open(dbName)
//we need this table to store the user track
const sql = 'CREATE TABLE IF NOT EXISTS uploadTrack\
(id TEXT, singer_name TEXT, singer_details TEXT, description TEXT,image_url TEXT, Track_name TEXT;'
await this.db.run(sql)
return this
console.log("Track open")
})()
}
/**
* checks to see if a set of login credentials are valid
* @param {String} username the username to check
* @param {String} password the password to check
* @returns {Boolean} returns true if credentials are valid
*/
async register(user, pass, email) {
Array.from(arguments).forEach( val => {
if(val.length === 0) throw new Error('missing field')
})
let sql = `SELECT COUNT(id) as records FROM artist WHERE user="${user}";`
const data = await this.db.get(sql)
if(data.records !== 0) throw new Error(`username "${user}" already in use`)
sql = `SELECT COUNT(id) as records FROM artist WHERE email="${email}";`
const emails = await this.db.get(sql)
if(emails.records !== 0) throw new Error(`email address "${email}" is already in use`)
pass = await bcrypt.hash(pass, saltRounds)
sql = `INSERT INTO artist(user, pass, email) VALUES("${user}", "${pass}", "${email}")`
await this.db.run(sql)
return true
}
async getAll() {
}
async tearDown() {
await this.db.close()
}
}