Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default [];
- import hasher from '../helpers/password';
- import CONFIG from '../config/config'
- import tokenMan from '../helpers/tokenMan';
- const id = 1 ;
- const is_admin = true;
- const is_buyer = false;
- const is_seller = false;
- const email = 'john@gmail.com';
- const token = tokenMan.tokenizer({id ,is_admin, is_seller, is_buyer});
- module.exports = {
- async makeAdmin(){
- const hash= await hasher.hashingPassword(CONFIG.adminPwd, 10);
- const admin = {
- token: token,
- id: id,
- first_name: 'john',
- last_name: 'doe',
- email: email,
- address: 'Lagos',
- password: hash,
- is_admin: is_admin,
- is_seller: is_seller,
- is_buyer: is_buyer
- }
- return admin;
- }
- }
- import users from '../models/userModel';
- import admin from '../models/adminModel';
- const User = {
- // User Sign Up
- async userSignUp(req, res) {
- const {
- error
- } = signUpFields(req.body);
- if (error) return res.status(400).json({
- status: 400,
- error: error.details[0].message
- });
- const id = users.length +1;
- const is_admin = false;
- const {
- first_name,
- last_name,
- email,
- password,
- address,
- is_seller,
- is_buyer
- } = req.body
- const hashed_password = await hasher.hashingPassword(password, 10);
- try {
- const newUser = {
- token: tokenMan.tokenizer({id, is_admin, is_seller, is_buyer}),
- id: id,
- email: email,
- first_name: first_name,
- last_name: last_name,
- password: hashed_password,
- address: address,
- is_admin: is_admin,
- is_buyer: Boolean(is_buyer == "true"),
- is_seller: Boolean(is_seller == "true"),
- }
- users.push(await admin.makeAdmin(), newUser);
- Promise.all(users).then(values =>{
- return res.status(201).json({
- status: 201,
- message: 'Successfully Signed Up',
- data: values
- })
- }).catch(err =>{
- throw err.message;
- });
- } catch (err) {
- return res.status(500).json({
- status: 500,
- error: err.message
- })
- }
- }
- }
- [ {
- id: 1,
- first_name: 'john',
- last_name: 'doe',
- email: 'john@gmail.com',
- ...
- {
- id: 1,
- email: 'yachim@gmail.com',
- first_name: 'yachim',
- last_name: 'zed',
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement