Take advantage of destructuring assignment for better code completion

This commit is contained in:
hiimgoodpack 2021-01-23 14:11:46 -05:00
parent ea15842113
commit bf46bb553c
Signed by: hiimgoodpack
GPG key ID: 4E0E62733C14AE69

View file

@ -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}`);