| 1 | const connection = require('../app/database'); |
| 2 | |
| 3 | class UserService { |
| 4 | async create(user) { |
| 5 | const { name, password } = user; |
| 6 | const statement = `INSERT INTO user (name, password) VALUES (?, ?);`; |
| 7 | const result = await connection.execute(statement, [name, password]); |
| 8 | |
| 9 | return result[0]; |
| 10 | } |
| 11 | |
| 12 | async getUserByName(name) { |
| 13 | const statement = `SELECT * FROM user WHERE name = ?;`; |
| 14 | const result = await connection.execute(statement, [name]); |
| 15 | |
| 16 | return result[0]; |
| 17 | } |
| 18 | |
| 19 | async updateAvatarUrlById(avatarUrl, userId) { |
| 20 | const statement = `UPDATE user SET avatar_url = ? WHERE id = ?;`; |
| 21 | const [result] = await connection.execute(statement, [avatarUrl, userId]); |
| 22 | return result; |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | module.exports = new UserService(); |
nothing calls this directly
no outgoing calls
no test coverage detected