Skip to content

Commit 898d148

Browse files
authored
Merge pull request #81 from CodeForBaltimore/superseeding
Creating random contacts
2 parents 1a44dd6 + eb47373 commit 898d148

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

sequelize/seeders/03-demo-entity.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const uuid = require('uuid4');
2+
const randomWords = require('random-words');
23
const entities = require('../data/entity.json');
34

45
module.exports = {
@@ -15,6 +16,65 @@ module.exports = {
1516
element.address = JSON.stringify(element.address);
1617
}
1718

19+
let i = 0;
20+
const entityNames = [
21+
"Springfield Bowlorama",
22+
"Springfield Nuclear Power Plant",
23+
"Androids Dungeon",
24+
"Kwik-E-Mart",
25+
"Krusty Burger",
26+
"Duff Brewery",
27+
"Aztech Theater",
28+
"The Copy Jalopy"
29+
];
30+
31+
for (let name of entityNames) {
32+
entities.push({
33+
id: uuid(),
34+
createdAt: new Date(),
35+
updatedAt: new Date(),
36+
name: name,
37+
address: JSON.stringify({
38+
street: [
39+
`123 ${randomWords()} St.`
40+
],
41+
city: "Baltimore",
42+
state: "MD",
43+
zip: "12345",
44+
latlng: [
45+
39.296399,
46+
-76.607842
47+
]
48+
}),
49+
description: randomWords(5)
50+
});
51+
}
52+
53+
// do {
54+
// let name = randomWords();
55+
// entities.push({
56+
// id: uuid(),
57+
// createdAt: new Date(),
58+
// updatedAt: new Date(),
59+
// name: name.charAt(0).toUpperCase() + name.slice(1),
60+
// address: JSON.stringify({
61+
// street: [
62+
// "123 Anyplace St."
63+
// ],
64+
// city: "Baltimore",
65+
// state: "MD",
66+
// zip: "12345",
67+
// latlng: [
68+
// 39.296399,
69+
// -76.607842
70+
// ]
71+
// }),
72+
// description: randomWords(5)
73+
// });
74+
// i++;
75+
// } while (i < 26);
76+
77+
1878
return queryInterface.bulkInsert('Entities', entities);
1979
},
2080
down: queryInterface => {

sequelize/seeders/04-demo-contact.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const uuid = require('uuid4');
2+
const randomWords = require('random-words');
23
const contacts = require('../data/contact.json');
34

45
module.exports = {
@@ -20,6 +21,49 @@ module.exports = {
2021
}
2122
}
2223

24+
let i = 0;
25+
do {
26+
const entityNames = [
27+
"Springfield Bowlorama",
28+
"Springfield Nuclear Power Plant",
29+
"Androids Dungeon",
30+
"Kwik-E-Mart",
31+
"Krusty Burger",
32+
"Duff Brewery",
33+
"Aztech Theater"
34+
];
35+
let name = randomWords();
36+
37+
let entityId = await queryInterface.sequelize.query(
38+
`SELECT id FROM ${process.env.DATABASE_SCHEMA}."Entities" WHERE name = '${entityNames[Math.floor(Math.random() * entityNames.length)]}'`
39+
);
40+
41+
let contact = {
42+
id: uuid(),
43+
createdAt: new Date(),
44+
updatedAt: new Date(),
45+
name: name.charAt(0).toUpperCase() + name.slice(1),
46+
email: JSON.stringify([
47+
{
48+
address: `${randomWords()}@test.test`,
49+
isPrimary: true
50+
}
51+
]),
52+
phone: JSON.stringify([
53+
{
54+
number: (Math.floor(Math.random() * Math.floor(100000000000))).toString(),
55+
isPrimary: true
56+
}
57+
])
58+
};
59+
60+
if(entityId[0][0] !== undefined) contact.EntityId = entityId[0][0].id;
61+
62+
contacts.push(contact);
63+
64+
i++;
65+
} while (i < 18);
66+
2367
return queryInterface.bulkInsert('Contacts', contacts);
2468
},
2569
down: queryInterface => {

0 commit comments

Comments
 (0)