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\"]}}"
@@ -59,9 +47,6 @@
"productDescription": "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>- 100% organic waxed 18 oz canvas<\/span><\/li>
- Full grain genuine leather accents<\/span><\/li>
- Adjustable shoulder straps<\/li>
- Lifetime 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\"]}}"
},
@@ -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"
},
{
@@ -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"
}
],
diff --git a/lib/common.js b/lib/common.js
index 56f8cd7..7c4841f 100644
--- a/lib/common.js
+++ b/lib/common.js
@@ -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)
]);
});
@@ -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;
+}