· 7 years ago · Feb 06, 2019, 07:54 PM
1CREATE TABLE IF NOT EXISTS
2 users(
3 id UUID PRIMARY KEY,
4 firstname VARCHAR(128) NOT NULL,
5 lastname VARCHAR(128) NOT NULL,
6 othername VARCHAR(128) NOT NULL,
7 email VARCHAR(128) UNIQUE NOT NULL,
8 phoneNumber VARCHAR(128) NOT NULL,
9 passportUrl VARCHAR(128) NOT NULL,
10 isAdmin BOOLEAN NOT NULL,
11 password VARCHAR(128) NOT NULL
12 )`;
13
14const createQuery = `INSERT INTO
15 users(id, firstname, lastname, othername, email, phoneNumber, passportUrl, isAdmin, password)
16 VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9)
17 returning *`;
18const values = [
19 uuidv4(),
20 req.body.firstname,
21 req.body.lastname,
22 req.body.othername,
23 req.body.email,
24 req.body.phoneNumber,
25 req.body.passportUrl,
26 false,
27 hashPassword
28];
29
30generateToken(id, isAdmin) {
31const token = jwt.sign({
32 userId: id,
33 role: isAdmin
34},
35 process.env.SECRET, { expiresIn: '1d' }
36);
37return token;
38}