forked from HowProgrammingWorks/DDD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.js
More file actions
35 lines (29 loc) · 915 Bytes
/
user.js
File metadata and controls
35 lines (29 loc) · 915 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
31
32
33
34
35
'use strict';
const common = { hash: require('../hash.js') };
const db = require('../db.js');
const users = db.crud('users');
module.exports = {
async read(id) {
const output = await users.read(id, ['id', 'login']);
return output.rows;
},
async create({ login, password }) {
const passwordHash = await common.hash(password);
const output = await users.create({ login, password: passwordHash });
return output.rows;
},
async update(id, { login, password }) {
const passwordHash = await common.hash(password);
const output = await users.update(id, { login, password: passwordHash });
return output.rows;
},
async delete(id) {
const output = await users.delete(id);
return output.rows;
},
async find(mask) {
const sql = 'SELECT login from users where login like $1';
const output = await users.query(sql, [mask]);
return output.rows;
},
};