From 6b4e43ce5edbd19480fd3984debd056b444630a6 Mon Sep 17 00:00:00 2001 From: Mathias Toussaint Date: Mon, 26 Oct 2015 14:23:03 +0800 Subject: [PATCH 1/3] Add .styl file --- api/functions/index.js | 1 + api/functions/products.js | 67 +++++++++++++++++++++++++++-- src/containers/Product/Product.styl | 55 +++++++++++++++++++++++ 3 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 src/containers/Product/Product.styl diff --git a/api/functions/index.js b/api/functions/index.js index 43f1094..c2c846c 100644 --- a/api/functions/index.js +++ b/api/functions/index.js @@ -1,2 +1,3 @@ export users from './users'; export products from './products'; +export product from './product'; diff --git a/api/functions/products.js b/api/functions/products.js index ec94ede..e483b86 100644 --- a/api/functions/products.js +++ b/api/functions/products.js @@ -1,23 +1,84 @@ import { Product } from '../models'; function getProducts(req, res) { - + res.json([{title: 'Title'}]); } function getProduct(req, res) { - + res.json(req.product.getPublic()); } function addProduct(req, res) { + const product = new Product({ + title: req.body.title, + description: req.body.description, + imageUrl: req.body.imageUrl, + price: req.body.price + }); + + product.save().then(() => { + res.json(product); + }, (error) => { + console.error(error); + res.status(500).json({msg: 'Contact an administrator', err: error}); + }); } function updateProduct(req, res) { + const product = {}; + const promises = []; + + if (req.body.title && req.body.title != req.product.title) { + promises.push(new Promise((resolve, reject) => { + product.title = req.body.title; + resolve(); + }, (error) => { + console.error(error); + res.status(500).json({msg: 'Contact an administrator', err: error}); + reject(); + })); + } + if (req.body.price && req.body.price !== req.product.price) { + promises.push(new Promise((resolve) => { + product.price = req.body.price; + resolve(); + }, (error) => { + console.error(error); + res.status(500).json({msg: 'Contact an administrator', err: error}); + reject(); + })); + } + + if (req.body.description && req.body.description !== req.product.description) { + promises.push(new Promise((resolve) => { + product.description = req.body.description; + resolve(); + }, (error) => { + console.error(error); + res.status(500).json({msg: 'Contact an administrator', err: error}); + reject(); + })); + } + + Promise.all(promises).then(() => { + req.product.merge(product).save().then((result) => { + res.json(req.product.getPublic()); + }, (error) => { + console.error(error); + res.status(400).json({msg: 'Something went wrong', err: error}); + }); + }); } function deleteProduct(req, res) { - + req.product.delete().then(() => { + res.json({msg: 'Account deleted'}); + }, (error) => { + console.error(error); + res.status(500).json({msg: 'Contact an administrator', err: error}); + }); } function search(req, res) { diff --git a/src/containers/Product/Product.styl b/src/containers/Product/Product.styl new file mode 100644 index 0000000..bf6c847 --- /dev/null +++ b/src/containers/Product/Product.styl @@ -0,0 +1,55 @@ +.productContainer { + padding: 20px; + display: flex; + flex-direction: column; + overflow: auto; +} + +.productContainer img { + padding: 20px; + max-width: 200px; + cursor: pointer; +} + +.mainInformations { + display: flex; + padding: 20px 0; + + &:not(:last-child) { + border-bottom: 1px solid #E7E7EC; + } +} + +.mainInformationsLeft { + display: flex; + flex-direction: column; + flex-basis: 100%; + padding: 0 20px; +} + +.mainInformationsLeft h3 { + color: #3585b5; + font-weight: 300; + margin: 0; + margin-bottom: 10px; +} + +.mainInformationsRight { + display: flex; + flex-direction: column; + flex-basis: 70%; + padding-left: 10%; +} + +.mainInformationsRight p { + font-size: 12px; + margin-bottom: 10px; + color: #999; +} + +.additionalInformations { + padding: 20px; + font-weight: 300; + font-size: 12px; + line-height: 24px; +} From eabc84a82d01120bb2445858146307997782bd20 Mon Sep 17 00:00:00 2001 From: Mathias Toussaint Date: Tue, 27 Oct 2015 12:40:24 +0800 Subject: [PATCH 2/3] Debug ApiClient bug --- api/functions/index.js | 2 +- api/models/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/functions/index.js b/api/functions/index.js index c2c846c..8132540 100644 --- a/api/functions/index.js +++ b/api/functions/index.js @@ -1,3 +1,3 @@ export users from './users'; export products from './products'; -export product from './product'; +//export product from './product'; diff --git a/api/models/index.js b/api/models/index.js index 6ab6ea6..c542341 100644 --- a/api/models/index.js +++ b/api/models/index.js @@ -1,3 +1,3 @@ export User from './User'; -export Product from './Product'; +//export Product from './Product'; export Email from './Email'; From cc2a70a9a01d0022087fadac36848c12570cbb95 Mon Sep 17 00:00:00 2001 From: Mathias Toussaint Date: Tue, 27 Oct 2015 12:47:43 +0800 Subject: [PATCH 3/3] functions products api --- api/functions/products.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/functions/products.js b/api/functions/products.js index e483b86..9f21f48 100644 --- a/api/functions/products.js +++ b/api/functions/products.js @@ -1,10 +1,16 @@ import { Product } from '../models'; function getProducts(req, res) { - res.json([{title: 'Title'}]); + res.json([{ + title: 'Title', + description: 'Nike shoes', + imageUrl: 'product.jpg', + price: '125$' + }]); } function getProduct(req, res) { + /* pourquoi product pop en orange ? */ res.json(req.product.getPublic()); }