-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathuser.js
More file actions
30 lines (24 loc) · 755 Bytes
/
user.js
File metadata and controls
30 lines (24 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'use strict';
const common = { hash: require('../hash.js') };
const db = require('../db.js');
const users = db.crud('users');
module.exports = {
async read(id) {
return await users.read(id, ['id', 'login']);
},
async create({ login, password }) {
const passwordHash = await common.hash(password);
return await users.create({ login, password: passwordHash });
},
async update(id, { login, password }) {
const passwordHash = await common.hash(password);
return await users.update(id, { login, password: passwordHash });
},
async delete(id) {
return await users.delete(id);
},
async find(mask) {
const sql = 'SELECT login from users where login like $1';
return await users.query(sql, [mask]);
},
};