Skip to content

Commit

Permalink
Fixed productAddedDate in test data
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvautin committed Feb 22, 2018
1 parent 61c59c8 commit ddaf235
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
21 changes: 0 additions & 21 deletions bin/testdata.json
Expand Up @@ -6,9 +6,6 @@
"productPrice": "188.00",
"productDescription": "<p style=\"margin-bottom: 25px; text-rendering: optimizeLegibility;\">Inspired by the timeless, functional style of your grandfather's work coat, the Foraker features brass buttons and 4 patch pockets. Crafted in Bristol, Tennessee, our 10oz organic duck canvas is light enough for an early summer morning, but rugged enough to handle your days work.<\/p><ul class=\"tabs-content\" style=\"margin-right: 0px; margin-bottom: 25px; margin-left: 20px; padding: 0px; text-rendering: optimizeLegibility;\"><li style=\"margin-bottom: 0px;\">100% Organic Duck Canvas.<\/li><\/ul>",
"productPublished": "true",
"productAddedDate": {
"$date": "2016-05-01T11:22:49.442Z"
},
"productTags": "organic, jacket",
"productOptions": "{\"Size\":{\"optName\":\"Size\",\"optLabel\":\"Select size\",\"optType\":\"select\",\"optOptions\":[\"S\",\"M\",\"L\",\"XL\"]},\"Colour\":{\"optName\":\"Colour\",\"optLabel\":\"Select colour\",\"optType\":\"select\",\"optOptions\":[\"Harvest\",\"Navy\"]}}",
"productImage": "/uploads/duckworth-jacket/woolfill-jacket_6c39ae23-c0c8-4821-85f4-4b5d64333c62_grande.jpg"
Expand All @@ -19,9 +16,6 @@
"productPrice": "48",
"productDescription": "<p style=\"margin-bottom: 25px; text-rendering: optimizeLegibility;\">A classic 5 panel hat with our United By Blue logo on the front and an adjustable strap to keep fit and secure. Made with recycled polyester and organic cotton mix.<\/p><ul style=\"margin-right: 0px; margin-bottom: 25px; margin-left: 20px; padding: 0px; text-rendering: optimizeLegibility;\"><li style=\"margin-bottom: 0px;\">Made in&nbsp;New Jersey<\/li><li style=\"margin-bottom: 0px;\">7oz Eco-Twill fabric:&nbsp;35% organic cotton, 65% recycled PET&nbsp;(plastic water and soda bottles)&nbsp;<\/li><li style=\"margin-bottom: 0px;\">Embossed leather patch<\/li><\/ul><ul class=\"tabs\" style=\"margin-right: 0px; margin-bottom: 25px; margin-left: 20px; padding: 0px; text-rendering: optimizeLegibility; color: rgb(28, 29, 29); font-family: Arapey, serif; line-height: 25.008px;\"><\/ul>",
"productPublished": "true",
"productAddedDate": {
"$date": "2016-07-10T05:01:15.744Z"
},
"productTags": "panel, cap",
"productOptions": "{\"colour\":{\"optName\":\"colour\",\"optLabel\":\"Select colour\",\"optType\":\"select\",\"optOptions\":[\"Heather green\",\"Burnt orange\",\"Slate grey\",\"Navy blue\"]}}",
"productImage": "/uploads/5-panel-cap/5-panel-hat_4ee20a27-8d5a-490e-a2fc-1f9c3beb7bf5_grande.jpg"
Expand All @@ -32,9 +26,6 @@
"productPrice": "310",
"productDescription": "<p style=\"margin-bottom: 25px; text-rendering: optimizeLegibility;\">The Mesabi Iron Range lies in northern Minnesota, a rugged and remote area known for its iron mines. The local residents who work these mines are proudly known as Iron Rangers, individuals with a sense of adventure and a determined personality. Originally designed to be worn in the iron mines, Iron Ranger work boots had to be as tough as the people who wore them in demanding conditions. Iron Ranger boots are built with a double layer of leaver over the toe to provide an extra measure of safety.<\/p><ul class=\"tabs-content\" style=\"margin-right: 0px; margin-bottom: 25px; margin-left: 20px; padding: 0px; text-rendering: optimizeLegibility;\"><li style=\"margin-bottom: 0px;\">6 inch, Amber Harness leather with Nitrile Cork sole.<\/li><\/ul>",
"productPublished": "true",
"productAddedDate": {
"$date": "2016-07-10T05:29:04.941Z"
},
"productTags": "ranger, boot, leather",
"productImage": "/uploads/ranger-boot/boot_grande.jpg",
"productOptions": "{\"size\":{\"optName\":\"size\",\"optLabel\":\"Select size\",\"optType\":\"select\",\"optOptions\":[\"7.5\",\"8\",\"8.5\",\"9\",\"9.5\",\"10\",\"10.5\",\"11\"]}}"
Expand All @@ -45,9 +36,6 @@
"productPrice": "138",
"productDescription": "<p style=\"margin-bottom: 25px; text-rendering: optimizeLegibility;\">Buttons are fussy. Sometimes you just want to roll out of bed, put on the pull over and get to the days work.&nbsp;Julie is 5'8\" and wearing a size small.<\/p><ul class=\"tabs-content\" style=\"margin-right: 0px; margin-bottom: 25px; margin-left: 20px; padding: 0px; text-rendering: optimizeLegibility;\"><li style=\"margin-bottom: 0px;\">100% Wool, Heavy 4 gauge thickness<\/li><li style=\"margin-bottom: 0px;\">Handmade in Nepal.<\/li><\/ul>",
"productPublished": "true",
"productAddedDate": {
"$date": "2016-05-01T11:23:08.374Z"
},
"productImage": "/uploads/whitney-pullover/WhitneyPullover_Full_58e7b8d6-b939-4701-9e1d-9d853dff60ed_grande.jpeg",
"productTags": "whitney, pullover",
"productOptions": "{\"size\":{\"optName\":\"size\",\"optLabel\":\"Select size\",\"optType\":\"select\",\"optOptions\":[\"S\",\"M\",\"L\",\"XL\"]}}"
Expand All @@ -59,9 +47,6 @@
"productDescription": "<p><span style=\"line-height: 1.42857;\">This durable backpack is ready for any adventure, large or small. Features adjustable and padded shoulder pads for comfort. Designed with a storm flap and a secured by two snap-button closure. Made with a waxed downpour proof exterior canvas and a soft cotton interior lining. Finished with brass hardware and genuine leather trimmings.<\/span><\/p><ul><li><span style=\"line-height: 1.42857;\">100% organic waxed 18 oz canvas<\/span><\/li><li><span style=\"line-height: 1.42857;\">Full grain genuine leather accents<\/span><\/li><li>Adjustable shoulder straps<\/li><li>Lifetime&amp;nbsp;Guarantee<\/li><\/ul>",
"productPublished": "true",
"productTags": "backpack, organic",
"productAddedDate": {
"$date": "2016-07-10T05:46:26.974Z"
},
"productImage": "/uploads/scout-backpack/scout-backpack_a035275d-8975-4a05-8456-5e1ec35f020f_grande.jpg",
"productOptions": "{\"colour\":{\"optName\":\"colour\",\"optLabel\":\"Select colour\",\"optType\":\"select\",\"optOptions\":[\"Navy\",\"Moss\",\"Nutmeg\",\"Khaki\"]}}"
},
Expand All @@ -73,9 +58,6 @@
"productPublished" : "true",
"productTags" : "backpack",
"productOptions" : "",
"productAddedDate": {
"$date": "2016-07-10T05:46:26.974Z"
},
"productImage" : "/uploads/hudderton-backpack/hudderton-backpack_dc8afb13-448b-49d9-a042-5a163a97de8f_590x.jpg"
},
{
Expand All @@ -86,9 +68,6 @@
"productPublished" : "true",
"productTags" : "shirt",
"productOptions" : "{\"Size\":{\"optName\":\"Size\",\"optLabel\":\"Select size\",\"optType\":\"select\",\"optOptions\":[\"S\",\"M\",\"L\"]}}",
"productAddedDate": {
"$date": "2016-07-10T05:46:26.974Z"
},
"productImage" : "/uploads/Ayres Chambray/chambray_5f232530-4331-492a-872c-81c225d6bafd_590x.jpg"
}
],
Expand Down
19 changes: 16 additions & 3 deletions lib/common.js
Expand Up @@ -629,7 +629,7 @@ exports.sampleData = (app) => {

// Add sample data
return Promise.all([
db.products.insertMany(jsonData.products),
db.products.insertMany(fixProductDates(jsonData.products)),
db.menu.insertOne(jsonData.menu)
]);
});
Expand All @@ -645,24 +645,37 @@ exports.testData = async (app) => {
Promise.all([
db.users.remove({}, {}),
db.customers.remove({}, {}),
db.products.remove({}, {})
db.products.remove({}, {}),
db.menu.remove({}, {})
])
.then(() => {
Promise.all([
db.users.insertMany(jsonData.users),
db.customers.insertMany(jsonData.customers),
db.products.insertMany(jsonData.products),
db.products.insertMany(fixProductDates(jsonData.products)),
db.menu.insertOne(jsonData.menu)
])
.then(() => {
resolve();
})
.catch((err) => {
console.log('Error inserting test data', err);
reject(err);
});
})
.catch((err) => {
console.log('Error removing existing test data', err);
reject(err);
});
});
};

// Adds current date to product added date when smashing into DB
function fixProductDates(products){
let index = 0;
products.forEach((product) => {
products[index].productAddedDate = new Date();
index++;
});
return products;
}

0 comments on commit ddaf235

Please sign in to comment.