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!
|
// WARNING: You should trust the server being used!
|
||||||
module.exports.users = {
|
module.exports.users = {
|
||||||
create: (server, user) => {
|
create: (server, {name = "", email = "", password = ""}) => {
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
const validationError =
|
const validationError =
|
||||||
module.exports.valid.username(user.name)
|
module.exports.valid.username(name)
|
||||||
|| module.exports.valid.email(user.email)
|
|| module.exports.valid.email(email)
|
||||||
|| module.exports.valid.password(user.password);
|
|| module.exports.valid.password(password);
|
||||||
if (validationError) {
|
if (validationError) {
|
||||||
rej(validationError);
|
rej(validationError);
|
||||||
return;
|
return;
|
||||||
|
@ -92,9 +92,9 @@ module.exports.users = {
|
||||||
urllib.request(api, {
|
urllib.request(api, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data: {
|
data: {
|
||||||
username: user.name,
|
username: name,
|
||||||
email: user.email,
|
email: email,
|
||||||
password: user.password
|
password: password
|
||||||
}
|
}
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
if (result.res.statusCode === 200)
|
if (result.res.statusCode === 200)
|
||||||
|
@ -114,11 +114,11 @@ module.exports.users = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
login: (server, user) => {
|
login: (server, {name = "", password = ""}) => {
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
const validationError =
|
const validationError =
|
||||||
module.exports.valid.username(user.name)
|
module.exports.valid.username(name)
|
||||||
|| module.exports.valid.password(user.password);
|
|| module.exports.valid.password(password);
|
||||||
if (validationError) {
|
if (validationError) {
|
||||||
rej(validationError);
|
rej(validationError);
|
||||||
return;
|
return;
|
||||||
|
@ -128,11 +128,11 @@ module.exports.users = {
|
||||||
urllib.request(api, {
|
urllib.request(api, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data: {
|
data: {
|
||||||
username: user.name,
|
username: name,
|
||||||
password: user.password
|
password: password
|
||||||
}
|
}
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
let newUser = Object.assign({}, user);
|
let newUser = {name: name, password: password};
|
||||||
const rawData = result.res.data.toString();
|
const rawData = result.res.data.toString();
|
||||||
if (rawData === rateLimited) {
|
if (rawData === rateLimited) {
|
||||||
rej(`Error when logging into account: ${rateLimited}`);
|
rej(`Error when logging into account: ${rateLimited}`);
|
||||||
|
|
Loading…
Reference in a new issue