Last active
October 27, 2019 14:40
-
-
Save Enigama/c36f7c48a76fcd65512eeb97863f30f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(procesenv='production', type, data){ | |
if(procesenv == 'production'){ | |
initAction(type, data); | |
} | |
if(procesenv == 'development'){ | |
initAction(type, data); | |
} | |
} | |
function initAction(type, data){ | |
switch(type){ | |
case 'POST': | |
userCreate(...data); | |
break; | |
case 'GET': | |
userInfo(...data); | |
break; | |
case 'DELETE': | |
userDelete(...data); | |
break | |
default: | |
console.log(type, data, 'some fail') | |
} | |
} | |
function userCreate(email, password){ | |
//users its array object user; | |
const data = {}; | |
if(!email || !password){ | |
console.log('email or password is bad', email, password) | |
data.status = 'error'; | |
return data; | |
}else{ | |
const isUser = users.findIndex(user.email === email) | |
if(isUser === -1){ | |
data.status = 'ok'; | |
data.user.id = Math.floor(Math.random()*1000); | |
data.user.email = email; | |
data.user.password = password; | |
return data; | |
} | |
} | |
function userInfo(id){ | |
const data = {}; | |
let hasUser = false; | |
//users its array object user; | |
users.foreach(user => { | |
if(user.id === id){ | |
hasUser = true | |
data.user = user; | |
}else{ | |
hasUser = false; | |
} | |
}) | |
if(!id || !hasId){ | |
data.status = 'error'; | |
return data; | |
}else{ | |
data.status = 'ok'; | |
return data; | |
} | |
} | |
function userDelete(id){ | |
let isUser = false | |
const data = {}; | |
users.forEach(user => { | |
if(user.id === id){ | |
delet user; | |
data.status = 'error'; | |
return data; | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment