const { ObjectID } = require('mongodb'); const jwt = require('jsonwebtoken'); const { Todo } = require('./../../models/todo'); const { User } = require('./../../models/user'); var bcrypt = require('bcrypt'); const tools = require('../../tools/general'); let myuserIdOne = ''; const userOneId = new ObjectID(); const userTwoId = new ObjectID(); // const userThreeId = new ObjectID(); // let mypwdcrypt = bcrypt.hash(mypwdchiaro, bcrypt.genSaltSync(12)) // .then((hashedPassword) => { // console.log('pwd=',hashedPassword); // }); // String(mypwdcrypt) let mypwdchiaro = 'mypassword@1A'; let mypwdcrypted = '$2b$12$mteST.isuWO0SNsfeZ0aCe.Dz3qwPh5SU8t9rc5SaPTkb3j0ywGv6' const date_login = new Date(); // const useragent = "auth Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36" const useragent = "node-superagent/2.3.0"; const users = [{ _id: userOneId, keyappid: process.env.KEY_APP_ID, lang: 'it', idapp: '1', email: 'paoloa.rena77@gmail.com', username: 'paoloar77B', password: mypwdcrypted, tokens: [{ access: 'auth', browser: useragent, token: jwt.sign({ _id: userOneId, access: 'auth' }, process.env.SIGNCODE).toString(), date_login }] }, { _id: userTwoId, keyappid: process.env.KEY_APP_ID, lang: 'it', idapp: '1', email: 'pa@com', password: mypwdcrypted, username: 'paoloar77C', tokens: [{ access: 'auth', browser: useragent, token: jwt.sign({ _id: userTwoId, access: 'auth' }, process.env.SIGNCODE).toString(), date_login }] }, { keyappid: process.env.KEY_APP_ID, // RECORD CHE VERRA' UTILIZZATO PER UNA NUOVA REGISTRAZIONE lang: 'it', idapp: '1', email: 'pao.loarena77@gmail.com', password: mypwdcrypted, username: 'paoloar77A' }]; const userjson = JSON.stringify(users[0]); // console.log('userjson=', userjson) const todos = [{ _id: new ObjectID(), category: "personal", statustodo: 0, completed_at: new Date(), created_at: new Date(), descr: "Primo Task Esempio", enableExpiring: false, expiring_at: new Date(), id_prev: "0", modified: false, modify_at: new Date(), pos: 1, priority: 1, progress: 0, userId: users[0]._id }, { _id: new ObjectID(), category: "personal", statustodo: 0, completed_at: new Date(), created_at: new Date(), descr: "Secondo Task Esempio", enableExpiring: false, expiring_at: new Date(), id_prev: "1", modified: false, modify_at: new Date(), pos: 2, priority: 1, progress: 0, userId: users[0]._id }, { _id: new ObjectID(), category: "personal", statustodo: 0, completed_at: new Date(), created_at: new Date(), descr: "Terzo Task Esempio", enableExpiring: false, expiring_at: new Date(), id_prev: "1", modified: false, modify_at: new Date(), pos: 3, priority: 1, progress: 0, userId: users[1]._id }, { // RECORD CHE VERRA' UTILIZZATO PER AGGIUNGERE UN NUOVO TASK _id: new ObjectID(), category: "personal", statustodo: 0, completed_at: new Date(), created_at: new Date(), descr: "Nuovo Quarto Task Esempio da Inserire", enableExpiring: false, expiring_at: new Date(), id_prev: "2", modified: false, modify_at: new Date(), pos: 4, priority: 1, progress: 0, userId: users[0]._id }]; const populateTodos = (done) => { Todo.deleteMany({}) .then(() => { var TodoOne = new Todo(todos[0]).save(); var TodoTwo = new Todo(todos[1]).save(); return Promise.all([TodoOne, TodoTwo]) }).then(() => { done() // tools.mylogshow('todos[0]', todos[0]._id); // tools.mylogshow('todos[1]', todos[1]._id); }); }; const populateUsers = (done) => { User.deleteMany({}) .then(() => { // console.log('users[0]', users[0]) var userOne = new User(users[0]).save(); var userTwo = new User(users[1]).save(); return Promise.all([userOne, userTwo]) }).then(() => done()); }; module.exports = { todos, populateTodos, users, populateUsers, userjson, mypwdcrypted, mypwdchiaro, date_login };