Take advantage of destructuring assignment for better code completion
This commit is contained in:
parent
ea15842113
commit
bf46bb553c
1 changed files with 13 additions and 13 deletions
26
index.js
26
index.js
|
@ -77,12 +77,12 @@ module.exports.valid = {
|
|||
*/
|
||||
// WARNING: You should trust the server being used!
|
||||
module.exports.users = {
|
||||
create: (server, user) => {
|
||||
create: (server, {name = "", email = "", password = ""}) => {
|
||||
return new Promise((res, rej) => {
|
||||
const validationError =
|
||||
module.exports.valid.username(user.name)
|
||||
|| module.exports.valid.email(user.email)
|
||||
|| module.exports.valid.password(user.password);
|
||||
module.exports.valid.username(name)
|
||||
|| module.exports.valid.email(email)
|
||||
|| module.exports.valid.password(password);
|
||||
if (validationError) {
|
||||
rej(validationError);
|
||||
return;
|
||||
|
@ -92,9 +92,9 @@ module.exports.users = {
|
|||
urllib.request(api, {
|
||||
method: "POST",
|
||||
data: {
|
||||
username: user.name,
|
||||
email: user.email,
|
||||
password: user.password
|
||||
username: name,
|
||||
email: email,
|
||||
password: password
|
||||
}
|
||||
}).then((result) => {
|
||||
if (result.res.statusCode === 200)
|
||||
|
@ -114,11 +114,11 @@ module.exports.users = {
|
|||
});
|
||||
},
|
||||
|
||||
login: (server, user) => {
|
||||
login: (server, {name = "", password = ""}) => {
|
||||
return new Promise((res, rej) => {
|
||||
const validationError =
|
||||
module.exports.valid.username(user.name)
|
||||
|| module.exports.valid.password(user.password);
|
||||
module.exports.valid.username(name)
|
||||
|| module.exports.valid.password(password);
|
||||
if (validationError) {
|
||||
rej(validationError);
|
||||
return;
|
||||
|
@ -128,11 +128,11 @@ module.exports.users = {
|
|||
urllib.request(api, {
|
||||
method: "POST",
|
||||
data: {
|
||||
username: user.name,
|
||||
password: user.password
|
||||
username: name,
|
||||
password: password
|
||||
}
|
||||
}).then((result) => {
|
||||
let newUser = Object.assign({}, user);
|
||||
let newUser = {name: name, password: password};
|
||||
const rawData = result.res.data.toString();
|
||||
if (rawData === rateLimited) {
|
||||
rej(`Error when logging into account: ${rateLimited}`);
|
||||
|
|
Loading…
Reference in a new issue