Skip to content

Commit

Permalink
🎉 major updates for mm to latest version of canon with react 16
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandersimoes committed Jan 31, 2019
1 parent 88e864e commit eefce3e
Show file tree
Hide file tree
Showing 84 changed files with 4,785 additions and 6,848 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ packages/*/static/reports
dockerfiles/nginx/certs/*
dockerfiles/nginx/conf.d/default.conf

# for VS Code specific configs
.vscode

# ignore private key file
mm-keyfile.json
mm-keyfile.json
2 changes: 1 addition & 1 deletion api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = function(app) {
return res.status(400).json("The password you entered is Incorrect.");
}
})
.catch(err => res.json(err));
.catch(err => res.json(err));
}
else {
return res.status(400).json("Not logged in!");
Expand Down
27 changes: 14 additions & 13 deletions api/companies.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const http = require("https");
const multer = require("multer");
const path = require("path");
const memoryStorage = multer.memoryStorage;
const storage = require("@google-cloud/storage");
const {Storage} = require("@google-cloud/storage");
const isAuthenticated = require("../api-helpers/authHelpers.js").isAuthenticated;
const Op = require("sequelize").Op;

Expand Down Expand Up @@ -42,12 +42,12 @@ module.exports = function(app) {
include: [db.Country],
order: [["createdAt", "DESC"]]
})
.then(companies => res.json(companies))
.catch(err => res.json(err));
.then(companies => res.json(companies))
.catch(err => res.json(err));
});

// Instantiate a storage client
const googleCloudStorage = storage({
const googleCloudStorage = new Storage({
projectId: process.env.GCLOUD_STORAGE_BUCKET,
keyFilename: process.env.GCLOUD_KEY_FILE
});
Expand All @@ -70,7 +70,7 @@ module.exports = function(app) {
}
});

app.get("/api/companies/:slug", async (req, res) => {
app.get("/api/companies/:slug", async(req, res) => {
const {slug} = req.params;
// const {id: uid} = req.user;
// console.log("companyid:", id)
Expand Down Expand Up @@ -107,7 +107,7 @@ module.exports = function(app) {
phone_number: json.phone_number,
description: json.bussiness_objetives,
address: json.address + json.address_line2 + json.city + json.country,
Country: {id:json.country_id, name:json.country},
Country: {id: json.country_id, name: json.country},
profile_image: json.photo_url,
ca_link: json.public_url,
catalog: json.catalog
Expand All @@ -124,11 +124,12 @@ module.exports = function(app) {
where: {slug},
include: [db.Country]
});
const user = await db.users.findOne({where:{id: company.uid}});
const user = await db.users.findOne({where: {id: company.uid}});
company.dataValues.activated = user.activated;

res.json(company);
} catch (error) {
}
catch (error) {
res.json(error);
}
}
Expand Down Expand Up @@ -160,9 +161,9 @@ module.exports = function(app) {
})
);
})
.catch(err => res.json({error: "File doesn't exist", resp: err}));
.catch(err => res.json({error: "File doesn't exist", resp: err}));
})
.catch(err => res.json(err));
.catch(err => res.json(err));
});

/** POST /:id - Uploads new image to google storage and updates DB
Expand Down Expand Up @@ -240,7 +241,7 @@ module.exports = function(app) {

});
})
.catch(err => res.json(err));
.catch(err => res.json(err));
});

/** POST / - Create a new entity */
Expand Down Expand Up @@ -292,8 +293,8 @@ module.exports = function(app) {
query: req.query
})
)
.catch(err => res.json({error: "Unable to delete company.", resp: err}));
.catch(err => res.json({error: "Unable to delete company.", resp: err}));
})
.catch(err => res.json(err));
.catch(err => res.json(err));
});
};
75 changes: 39 additions & 36 deletions api/trades.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ const isAuthenticated = require("../api-helpers/authHelpers.js").isAuthenticated
const Op = require("sequelize").Op;

async function isCompanyAccountActivated(company, db) {
const {uid} = company;
const user = await db.users.findOne({where: {id: uid}});
return user.activated;
const {uid} = company;
const user = await db.users.findOne({where: {id: uid}});
return user.activated;
}

async function filterTradesByCompanyActivated(trades, db) {
const tradesWithActivatedStatus = await Promise.all(trades.map(async trade => {return {trade, activated: await isCompanyAccountActivated(trade.Company, db)}}));
const tradesWithActivatedStatus = await Promise.all(trades.map(async trade => ({trade, activated: await isCompanyAccountActivated(trade.Company, db)})));
return tradesWithActivatedStatus.filter(data => data.activated).map(data => data.trade);
}

Expand Down Expand Up @@ -48,15 +48,13 @@ module.exports = function(app) {
db.Company.findOne({
where: {slug},
include: [db.Country]
}).then(company => {
return db.Trade.findAll({
where: {
company_id: company.id
},
include: [db.Product, db.Country]
}).then(trades => res.json(trades));
})
.catch(() => res.json([]));
}).then(company => db.Trade.findAll({
where: {
company_id: company.id
},
include: [db.Product, db.Country]
}).then(trades => res.json(trades)))
.catch(() => res.json([]));
});

app.post("/api/trades/company/:companyId", isAuthenticated, (req, res) => {
Expand Down Expand Up @@ -86,10 +84,10 @@ module.exports = function(app) {
return Promise.all(tPromises).then(() => {
res.json({msg: "done."});
})
.catch(err => res.json(err));
.catch(err => res.json(err));
});
})
.catch(err => res.json(err));
.catch(err => res.json(err));
});

app.delete("/api/trades/company/:companyId/product/:productId", isAuthenticated, (req, res) => {
Expand All @@ -109,42 +107,47 @@ module.exports = function(app) {
}).then(() =>
res.json({success: true})
)
.catch(err => res.json(err));
.catch(err => res.json(err));
})
.catch(err => res.json(err));
.catch(err => res.json(err));

});

// TODO: rename to "/api/trades/byCountry/:countryId"
app.get("/api/trades/country/:countryId", async (req, res) => {
try {
const {countryId: country_id} = req.params;
const trades = await db.Trade.findAll({
where: {
country_id
},
include: [db.Product, db.Company]
});
const activatedTrades = await filterTradesByCompanyActivated(trades, db);
res.json(activatedTrades);
} catch (error) {
res.json(error)
}
app.get("/api/trades/country/:countryId", async(req, res) => {
try {
const {countryId: country_id} = req.params;
const trades = await db.Trade.findAll({
where: {
country_id
},
include: [db.Product, db.Company],
limit: 120
});
const activatedTrades = await filterTradesByCompanyActivated(trades, db);
res.json(activatedTrades);
}
catch (error) {
res.json(error);
}
});

// TODO: rename to "/api/trades/byProduct/:productId"
app.get("/api/trades/product/:productId", async (req, res) => {
app.get("/api/trades/product/:productId", async(req, res) => {
try {
const {productId: product_id} = req.params;
console.log("product_id!!!", product_id, "db.Trade", db.Trade);
console.log("db.Country", db.Country);
const trades = await db.Trade.findAll({
where: {
product_id: {$ilike: `${product_id}%`}
product_id: {[Op.iLike]: `${product_id}%`}
},
include: [db.Country, db.Company]
});
const activatedTrades = await filterTradesByCompanyActivated(trades, db);
res.json(activatedTrades);
} catch (error) {
}
catch (error) {
res.json(error);
}
});
Expand All @@ -161,9 +164,9 @@ module.exports = function(app) {
},
include: [db.Country, db.Product]
}).then(trades => res.json(trades))
.catch(err => res.json(err));
.catch(err => res.json(err));
})
.catch(err => res.json(err));
.catch(err => res.json(err));
});

app.get("/api/trades/ca_country/:countryId", (req, res) => {
Expand Down
1 change: 0 additions & 1 deletion app/App.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@import "./Variables";
@import 'react-select/dist/react-select.css';
body {
margin: 0;
font-family: var(--libreFranklin);
Expand Down
36 changes: 18 additions & 18 deletions app/App.jsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import React from "react";
import React, {Component} from "react";
import {connect} from "react-redux";
import {isAuthenticated} from "@datawheel/canon-core";
import NavBar from "./components/NavBar.jsx";
import Footer from "./components/Footer.jsx";
import OnboardingOverlay from "./components/OnboardingOverlay";
import "./App.css";
import {toggleOverlay} from "./actions/onboardingActions";
import Helmet from "react-helmet";
import header from "./helmet.js";
import header from "helpers/helmet.js";
import NavBar from "components/NavBar.jsx";
import Footer from "components/Footer.jsx";
import OnboardingOverlay from "components/OnboardingOverlay";
import {toggleOverlay} from "actions/onboardingActions";
import "./App.css";

class App extends React.Component {
class App extends Component {
constructor(props) {
super(props);
console.log("this.props.location.query.source", this.props.location.query.source);
if (this.props.location.query.source === "oec") {
this.props.toggleOverlay();
}
}

render() {
const {isOpen} = this.props;
return (
<div className={isOpen ? "overlayOpen overlay-bg" : "overlay-bg"}>
<Helmet title={ header.title } link={ header.link } meta={ header.meta } />
<NavBar location={this.props.location} />
<OnboardingOverlay query={this.props.location.query}/>
<div className="main-content">
{this.props.children}
<Footer />
</div>
console.log("isOpen:", isOpen);
return <div className={isOpen ? "overlayOpen overlay-bg" : "overlay-bg"}>
<Helmet title={ header.title } link={ header.link } meta={ header.meta } />
<NavBar location={this.props.location} />
<OnboardingOverlay query={this.props.location.query} />
<div className="main-content">
<div>{this.props.children}</div>
<Footer />
</div>
);
</div>;
}
}

Expand Down
Loading

0 comments on commit eefce3e

Please sign in to comment.