SHARE
TWEET

Untitled

a guest Jun 17th, 2019 119 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export default [];
  2.      
  3. import hasher from '../helpers/password';
  4. import CONFIG from '../config/config'
  5. import tokenMan from '../helpers/tokenMan';
  6.  
  7. const id = 1 ;
  8. const is_admin = true;
  9. const is_buyer = false;
  10. const is_seller = false;
  11. const email = 'john@gmail.com';
  12. const token = tokenMan.tokenizer({id ,is_admin, is_seller, is_buyer});
  13.  
  14. module.exports = {
  15.     async makeAdmin(){
  16.         const hash= await hasher.hashingPassword(CONFIG.adminPwd, 10);
  17.            const admin = {
  18.                 token: token,
  19.                 id: id,
  20.                 first_name: 'john',
  21.                 last_name: 'doe',
  22.                 email: email,
  23.                 address: 'Lagos',
  24.                 password: hash,
  25.                 is_admin: is_admin,
  26.                 is_seller: is_seller,
  27.                 is_buyer: is_buyer
  28.             }
  29.         return admin;
  30.     }
  31. }
  32.      
  33. import users from '../models/userModel';
  34. import  admin from '../models/adminModel';
  35.  
  36. const User = {
  37.  
  38.     // User Sign Up
  39.     async userSignUp(req, res) {
  40.         const {
  41.             error
  42.         } = signUpFields(req.body);
  43.  
  44.         if (error) return res.status(400).json({
  45.             status: 400,
  46.             error: error.details[0].message
  47.         });
  48.  
  49.         const id = users.length +1;
  50.         const is_admin = false;
  51.         const {
  52.             first_name,
  53.             last_name,
  54.             email,
  55.             password,
  56.             address,
  57.             is_seller,
  58.             is_buyer
  59.         } = req.body
  60.  
  61.         const hashed_password = await hasher.hashingPassword(password, 10);
  62.  
  63.         try {
  64.  
  65.             const newUser =  {
  66.             token: tokenMan.tokenizer({id, is_admin, is_seller, is_buyer}),
  67.             id: id,
  68.             email: email,
  69.             first_name: first_name,
  70.             last_name: last_name,
  71.             password: hashed_password,
  72.             address: address,
  73.             is_admin: is_admin,
  74.             is_buyer: Boolean(is_buyer == "true"),
  75.             is_seller: Boolean(is_seller == "true"),
  76.         }
  77.  
  78.             users.push(await admin.makeAdmin(), newUser);
  79.             Promise.all(users).then(values =>{
  80.             return res.status(201).json({
  81.                 status: 201,
  82.                 message: 'Successfully Signed Up',
  83.                 data: values
  84.             })
  85.             }).catch(err =>{
  86.                 throw err.message;
  87.             });
  88.  
  89.         } catch (err) {
  90.             return res.status(500).json({
  91.                 status: 500,
  92.                 error: err.message
  93.             })
  94.         }
  95.     }
  96. }
  97.      
  98. [ {
  99.     id: 1,
  100.     first_name: 'john',
  101.     last_name: 'doe',
  102.     email: 'john@gmail.com',
  103. ...
  104.   {
  105.     id: 1,
  106.     email: 'yachim@gmail.com',
  107.     first_name: 'yachim',
  108.     last_name: 'zed',
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top