Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 01f7ef5

Browse files
committed
yarn link
1 parent 125bd22 commit 01f7ef5

File tree

3 files changed

+31
-47
lines changed

3 files changed

+31
-47
lines changed
Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,19 @@
1-
'use strict';
1+
exports.up = function (pgm) {
2+
pgm.createExtension('uuid-ossp')
3+
pgm.createTable('users', {
4+
id: { type: 'uuid', primaryKey: true },
5+
name: { type: 'string', unique: true, notNull: true },
6+
email: { type: 'string', unique: true, notNull: true },
7+
password: { type: 'string', notNull: true },
8+
division: { type: 'string', notNull: true }
9+
})
10+
}
211

3-
var dbm;
4-
var type;
5-
var seed;
6-
7-
/**
8-
* We receive the dbmigrate dependency from dbmigrate initially.
9-
* This enables us to not have to rely on NODE_PATH.
10-
*/
11-
exports.setup = function(options, seedLink) {
12-
dbm = options.dbmigrate;
13-
type = dbm.dataType;
14-
seed = seedLink;
15-
};
16-
17-
exports.up = function(pgm) {
18-
pgm.createExtension("uuid-ossp")
19-
pgm.createTable("users", {
20-
id: { type: "uuid", primaryKey: true },
21-
name: { type: "string", unique: true, notNull: true },
22-
email: { type: "string", unique: true, notNull: true },
23-
password: { type: "string", notNull: true },
24-
division: { type: "string", notNull: true }
25-
});
26-
};
27-
28-
exports.down = function(pgm) {
29-
pgm.dropTable("users");
30-
pgm.dropExtension("uuid-ossp")
31-
};
12+
exports.down = function (pgm) {
13+
pgm.dropTable('users')
14+
pgm.dropExtension('uuid-ossp')
15+
}
3216

3317
exports._meta = {
34-
"version": 1
35-
};
18+
version: 1
19+
}

server/database/auth.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
const db = require("./db")
1+
const db = require('./db')
22

33
const ret = {
44
getUser: ({ id }) => {
5-
return db.query("SELECT * FROM users WHERE id = $1", [id])
5+
return db.query('SELECT * FROM users WHERE id = $1', [id])
66
.then(res => res.rows[0])
77
},
88
makeUser: ({ id, name, email, division, password }) => {
9-
return db.query("INSERT INTO users (id, name, email, division, password) VALUES ($1, $2, $3, $4, $5) RETURNING *",
10-
[id, name, email, division, password]
11-
)
9+
return db.query('INSERT INTO users (id, name, email, division, password) VALUES ($1, $2, $3, $4, $5) RETURNING *',
10+
[id, name, email, division, password]
11+
)
1212
.then(res => res.rows[0])
1313
},
1414
updateUser: ({ id, name, email, division, password }) => {
1515
return ret.getUser({ id })
1616
.then(user => {
17-
const upd = {name, email, division, password};
17+
const upd = { name, email, division, password }
1818
Object.keys(upd).forEach(key => {
19-
if(upd[key] === undefined) delete upd[key];
20-
});
19+
if (upd[key] === undefined) delete upd[key]
20+
})
2121

22-
user = Object.assign(user, upd);
22+
user = Object.assign(user, upd)
2323

24-
return db.query("UPDATE users SET name = $1, email = $2, division = $3, password = $4 WHERE id = $5 RETURNING *",
25-
[user.name, user.email, user.division, user.password, user.id]
26-
)
24+
return db.query('UPDATE users SET name = $1, email = $2, division = $3, password = $4 WHERE id = $5 RETURNING *',
25+
[user.name, user.email, user.division, user.password, user.id]
26+
)
2727
})
2828
.then(res => res.rows[0])
2929
}
3030
}
3131

32-
module.exports = ret;
32+
module.exports = ret

server/database/db.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const connectionString = process.env.DATABASE_URL;
1+
const connectionString = process.env.DATABASE_URL
22

3-
const { Pool } = require("pg")
3+
const { Pool } = require('pg')
44
const pool = new Pool({
55
connectionString
66
})

0 commit comments

Comments
 (0)