UserStorage.js
939 Bytes
'use strict';
class UserStorage {
//더미데이터
// # = private 변수로 은닉화
static #users = {
id: ["jeongmin", "jumi"],
password: ["1234", "1234"],
name: ["정민", "주미"],
};
static getUsers(...fields) {
const users = this.#users;
const newUsers = fields.reduce((newUsers, field) => {
if (users.hasOwnProperty(field)) {
newUsers[field] = users[field];
}
return newUsers;
}, {});
return newUsers;
}
static getUserInfo(id) {
const users = this.#users;
const idx = users.id.indexOf(id);
const userKeys = Object.keys(users); // [id, password, name]
const userInfo = userKeys.reduce((newUser, info) => {
newUser[info] = users[info][idx];
return newUser;
}, {});
return userInfo;
}
}
module.exports = UserStorage;