forked from HowProgrammingWorks/DDD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.js
29 lines (25 loc) · 802 Bytes
/
user.js
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
({
async read(id) {
const output = await db('users').read(id, ['id', 'login']);
return output.rows;
},
async create({ login, password }) {
const passwordHash = await common.hash(password);
const output = await db('users').create({ login, password: passwordHash });
return output.rows;
},
async update(id, { login, password }) {
const passwordHash = await common.hash(password);
const output = await db('users').update(id, { login, password: passwordHash });
return output.rows;
},
async delete(id) {
const output = await db('users').delete(id);
return output.rows;
},
async find(mask) {
const sql = 'SELECT login from users where login like $1';
const output = await db('users').query(sql, [mask]);
return output.rows;
},
});