Skip to content

Commit

Permalink
update investor logic
Browse files Browse the repository at this point in the history
  • Loading branch information
musubipapi committed Jan 31, 2023
1 parent 6b05d37 commit f796fdf
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 24 deletions.
26 changes: 15 additions & 11 deletions components/InvestorModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@ const Modal = ({ investors, additionalInvestors, setAdditionalInvestors }) => {
setIsLoading(false);
return;
}
const data = await ky
.post(`${process.env.NEXT_PUBLIC_BASE_URL}${GET_INVESTOR_BY_SLUG}`, {
json: { slug },
})
.json();
if (data) {
setInvestorData(data);
setVerified(true);
setError([false, ""]);
} else {
setError([true, "This slug does not exist"]);
try {
const data = await ky
.post(`${process.env.NEXT_PUBLIC_BASE_URL}${GET_INVESTOR_BY_SLUG}`, {
json: { slug },
})
.json();
if (data) {
setInvestorData(data);
setVerified(true);
setError([false, ""]);
} else {
setError([true, "This slug does not exist"]);
}
} catch (err) {
setError([true, "This is an invalid investor"]);
}
setIsLoading(false);
};
Expand Down
2 changes: 2 additions & 0 deletions pages/api/confirm-investors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default withIronSessionApiRoute(
// Transactions require all reads be done before writes
const validateRef = db.collection("MTurk").doc(profileId);
const validateDoc = await t.get(validateRef);
console.log(validateDoc.data());
const companyCode = validateDoc.data()?.crunchbaseSlug;
const founderHash = crypto
.createHash("sha256")
Expand Down Expand Up @@ -56,6 +57,7 @@ export default withIronSessionApiRoute(
id: i?.identifier?.uuid,
slug: i?.identifier?.permalink,
}));
console.log(validateDoc.data().additionalInvestors);
if (validateDoc.data().additionalInvestors) {
investorsObjs = investorsObjs.concat(
validateDoc.data().additionalInvestors
Expand Down
28 changes: 18 additions & 10 deletions pages/api/crunchbase/investor-by-slug.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ export default async function getCompany(req, res) {
try {
const { slug } = req.body;
const properties = await getInvestorBySlug(slug);
return res.status(200).json(
properties.identifier
? {
id: properties?.identifier?.uuid ?? null,
image: properties?.image_url ?? null,
name: properties?.identifier?.value ?? null,
slug: properties?.identifier?.permalink ?? null,
}
: null
);
if (
properties.investor_type &&
properties.investor_type &&
!properties.investor_type.includes("angel")
) {
return res.status(200).json(
properties.identifier
? {
id: properties?.identifier?.uuid ?? null,
image: properties?.image_url ?? null,
name: properties?.identifier?.value ?? null,
slug: properties?.identifier?.permalink ?? null,
}
: null
);
} else {
throw Error("invalid Investor");
}
} catch (error) {
console.error(error);
res.status(500).json({ error: error.response || error });
Expand Down
2 changes: 1 addition & 1 deletion pages/form/[authToken].js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default function ConfirmInvestors({ investors = [], name, company }) {
`${process.env.NEXT_PUBLIC_BASE_URL}${ADD_ADDITIONAL_INVESTORS}`,
{
json: {
additionalInvestors: additionalInvestors.map((data) => data.name),
additionalInvestors: additionalInvestors.map((data) => data.slug),
},
}
);
Expand Down
4 changes: 2 additions & 2 deletions pages/login/callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export const getServerSideProps = withIronSessionSsr(
const emailRes = await getEmail(authToken);
const profileRes = await getProfile(authToken);
req.session.profile = {
first: profileRes.localizedFirstName,
last: profileRes.localizedLastName,
first: "Roy" || profileRes.localizedFirstName,
last: "Bahat" || profileRes.localizedLastName,
id: profileRes.id,
image:
profileRes?.profilePicture?.["displayImage~"]?.elements?.[3]
Expand Down
1 change: 1 addition & 0 deletions utils/crunchbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export async function getInvestors(companyId) {
?.investors;
for (const investorSlug of additionalInvestorsSlugs) {
const investorData = await getInvestorBySlug(investorSlug);
console.log(investorData);
investors.push(investorData);
}
}
Expand Down

0 comments on commit f796fdf

Please sign in to comment.