Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion sequelize/data/contact.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@
"number": "1234567890",
"isPrimary": true
}
]
],
"EntityId": "The Leftorium"
},
{
"name": "Moe Szyslak",
"email": [
{
"address": "moe@moestavern.com",
"isPrimary": true
}
],
"phone": [
{
"number": "0987654321",
"isPrimary": true
}
],
"EntityId": "Moes Tavern"
}
]
16 changes: 16 additions & 0 deletions sequelize/data/entity.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,21 @@
]
},
"description": "Everything for the left handed man, woman, and child!"
},
{
"name": "Moes Tavern",
"address": {
"street": [
"123 Anyplace St."
],
"city": "Baltimore",
"state": "MD",
"zip": "12345",
"latlng": [
39.296399,
-76.607842
]
},
"description": "Home of the Flaming Moe!"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const uuid = require('uuid4');
const entities = require('../data/entity.json');

module.exports = {
up: queryInterface => {
up: async queryInterface => {

for (const element of entities) {
const id = uuid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const uuid = require('uuid4');
const contacts = require('../data/contact.json');

module.exports = {
up: queryInterface => {
up: async queryInterface => {
for (const element of contacts) {
const id = uuid();

Expand All @@ -11,6 +11,13 @@ module.exports = {
element.updatedAt = new Date();
element.email = JSON.stringify(element.email);
element.phone = JSON.stringify(element.phone);

if (element.EntityId) {
const entityId = await queryInterface.sequelize.query(
`SELECT id FROM ${process.env.DATABASE_SCHEMA}."Entities" WHERE name = '${element.EntityId}'`
);
element.EntityId = entityId[0][0].id;
}
}

return queryInterface.bulkInsert('Contacts', contacts);
Expand Down