Created
July 15, 2019 05:29
-
-
Save harrisonmalone/465d24e052c8d2e57a41b666c1801c2e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const mongoose = require('mongoose') | |
| const User = require('../models/User') | |
| const Program = require('../models/Program') | |
| const Client = require('../models/Client') | |
| const Project = require('../models/Project') | |
| const Resource = require('../models/Resource') | |
| const { userData, programData, clientData, projectData, resourceData } = require('./seedData') | |
| const addEmployee = async (user, client) => { | |
| client | |
| } | |
| const seedClients = async () => { | |
| console.log('Seeding Clients'); | |
| try { | |
| return clientData.map(async (companyName) => { | |
| const newClient = await Client.create({ | |
| _id: new mongoose.Types.ObjectId(), | |
| companyName: companyName, | |
| }) | |
| return newClient | |
| }) | |
| } catch(err) { console.log(err) } | |
| } | |
| // const seedUsers = async () => { | |
| // try { | |
| // console.log('Seeding Users'); | |
| // // const users = await User.find() | |
| // // console.log(users); | |
| // const seededClient = await Client.find() | |
| // await console.log(`seeded Client: {seededClient}`); | |
| // // console.log(seededClient[0]._id); | |
| // const superAdminUser = await User.create({ | |
| // _id: new mongoose.Types.ObjectId(), | |
| // email: 'superadmin@admin.com', | |
| // password: 'password', | |
| // role: 'superadmin', | |
| // clientID: seededClient._id | |
| // }) | |
| // userData.map( async (user) => { | |
| // const newUser = await User.create({ | |
| // _id: new mongoose.Types.ObjectId(), | |
| // email: user.email, | |
| // password: user.password, | |
| // role: user.role, | |
| // }) | |
| // // Client.employees.push(newUser._id) | |
| // // console.log({message: 'Seeded Student User', result: newUser}); | |
| // }) | |
| // } catch(err) { console.log(err.message, err.stack) } | |
| // } | |
| const seedDatabase = async (req, res) => { | |
| console.log('Destroying Data...') | |
| try { | |
| await User.deleteMany() | |
| await Program.deleteMany() | |
| await Client.deleteMany() | |
| await Project.deleteMany() | |
| await Resource.deleteMany() | |
| console.log('Starting Database Seed...'); | |
| try { | |
| const clientPromises = await seedClients() | |
| const clients = await Promise.all(clientPromises) | |
| console.log(clients) | |
| } catch(err) { res.send(err) } | |
| } catch(err) { return res.send(err) } | |
| return res.json({ message: 'Finished Seeding Database' }) | |
| } | |
| module.exports = { | |
| seedDatabase | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment