Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
Add prijava-firmi page (and some other stuff)
Browse files Browse the repository at this point in the history
  • Loading branch information
Allypost committed Jan 26, 2021
1 parent 7654185 commit 96fc936
Show file tree
Hide file tree
Showing 13 changed files with 1,228 additions and 288 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ yarn-install:
docker/yarn install

build: yarn-install
docker/yarn build -c nuxt.config.build
rm -rf "$(FINAL_OUTPUT_DIR)"
mv "$(BUILD_OUTPUT_DIR)" "$(FINAL_OUTPUT_DIR)"
mkdir -p "$(FINAL_OUTPUT_DIR)" && \
docker/yarn build -c nuxt.config.build && \
mv "$(FINAL_OUTPUT_DIR)" "$(FINAL_OUTPUT_DIR).old" && \
mv "$(BUILD_OUTPUT_DIR)" "$(FINAL_OUTPUT_DIR)" && \
rm -rf "$(FINAL_OUTPUT_DIR).old"

clean:
rm -rf $(NODE_MODULES) .nuxt
Expand Down
7 changes: 7 additions & 0 deletions api/graphql/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
resumeData,
basicResumeData,
companyDataWithMeta,
industry,
} from "./data";
import {
createObject,
Expand All @@ -32,6 +33,12 @@ export const participantsQuery = () => ({
}) } }`,
});

export const industriesQuery = () => ({
query: `{ ${ createObject({
industries: industry,
}) } }`,
});

export const participantsWithEventsQuery = () => ({
query: `{ ${ createObject({
companies: companyDataWithMeta,
Expand Down
1 change: 1 addition & 0 deletions api/helpers/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const response =
error,
data,
status,
ts: Date.now(),
})
;

Expand Down
6 changes: 2 additions & 4 deletions api/helpers/token.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import {
verify,
} from "jsonwebtoken";
import {
fixCompany,
} from "../../helpers/company";
import {
keysFromSnakeToCamelCase,
} from "../../helpers/object";
import {
basicUserQuery,
currentUserQuery,
} from "../graphql/queries";
import CompanyService from "../services/company-service";
import {
getSetting,
} from "./settings";
Expand Down Expand Up @@ -123,7 +121,7 @@ export const fetchAuthenticatedUser = async (reqOrToken, fullUser = false) => {
const { data: rawParticipants = [] } = await internalRequest("get", "/companies/participants");
const participantIds = new Set(rawParticipants.map(({ id }) => id));

user.companies = companies.filter(({ id }) => participantIds.has(id)).map(fixCompany);
user.companies = companies.filter(({ id }) => participantIds.has(id)).map(CompanyService.fixCompany);
}

return user;
Expand Down
223 changes: 59 additions & 164 deletions api/routes/companies.js
Original file line number Diff line number Diff line change
@@ -1,110 +1,41 @@
import {
fixCompany,
} from "../../helpers/company";
import {
keysFromSnakeToCamelCase,
} from "../../helpers/object";
import {
cachedFetcher,
} from "../helpers/fetchCache";
import {
HttpStatus,
internalRequest,
} from "../helpers/http";
import {
participantsQuery,
participantEventsQuery,
} from "../graphql/queries";
import {
ApiError,
Router,
} from "../helpers/route";
import {
graphQlQuery,
} from "../helpers/axios";
import CompanyService from "../services/company-service";
import CompanyEventsService from "../services/company-events-service";
import VatValidator from "../services/vat-validator";

const router = new Router();

const cacheForMs = 15 * 1000;

router.get("/participants", cachedFetcher(cacheForMs, async () => {
const { companies } = await graphQlQuery(participantsQuery());

if (!companies) {
return [];
}
return await CompanyService.fetchListAll();
}));

return companies.map(fixCompany);
router.get("/industries", cachedFetcher(cacheForMs, async () => {
return await CompanyService.fetchIndustries();
}));

router.get("/events/all", cachedFetcher(cacheForMs, async () => {
const { companies, ...eventList } = await graphQlQuery(participantEventsQuery());

const { data: panels } = await internalRequest("get", "/panels/list/with-info");

const events = {
panels,
...eventList,
};

return keysFromSnakeToCamelCase({
companies: companies.map(fixCompany),
...events,
});
return await CompanyEventsService.listAll();
}));

router.get("/events", cachedFetcher(cacheForMs, async () => {
const { data } = await internalRequest("get", "/companies/events/all");
const { companies, ...events } = data;

const oneHourAgo = new Date();
oneHourAgo.setHours(oneHourAgo.getHours() - 1);

const eventHasNotPassed =
(
{
date,
occuresAt,
occures_at: occuresAtOther,
},
) =>
new Date(date || occuresAt || occuresAtOther) >= oneHourAgo
;

const removePassedEvents =
(
[
key,
events,
],
) =>
[
key,
events.filter(eventHasNotPassed),
]
;

const filteredEvents = Object.fromEntries(
Object
.entries(events)
.map(removePassedEvents)
,
);

return {
companies,
...filteredEvents,
};
return await CompanyEventsService.listNotPassed();
}));

router.get("/events/panel/:id", cachedFetcher(cacheForMs, async ({ params }) => {
const { id } = params;
const { data: panel } = await internalRequest("get", `/panels/full-info/${ id }`);

return {
...panel,
occuresAt: panel.date,
};
return await CompanyEventsService.listPanelsForCompany(id);
}, ({ params }) => {
return params.id;
}));
Expand All @@ -113,105 +44,69 @@ router.get("/events/:type/:id", cachedFetcher(cacheForMs, async ({ params }) =>
const { type, id } = params;

if (!type || !id) {
throw new ApiError("no-params", HttpStatus.Error.Forbidden, [
throw new ApiError("no-params", HttpStatus.Error.Client.Forbidden, [
"Type and ID are required params",
]);
}

const typeTransformer = (type) => {
switch (type) {
case "presentation":
case "talk":
return "presentations";
case "workshop":
return "workshops";
default:
return `${ type }s`;
}
};

const transformedType = typeTransformer(type);

const { companies, [transformedType]: objList } = await graphQlQuery(participantEventsQuery());

if (!objList) {
throw new ApiError("no-type", HttpStatus.Error.Forbidden, [
`Event type not found: ${ transformedType }`,
]);
}

const obj = objList.find(({ id: i }) => Number(i) === Number(id));

if (!obj) {
throw new ApiError("event-not-found", HttpStatus.Error.Client.NotFound, [
"Event not found",
]);
}

return keysFromSnakeToCamelCase({
...obj,
company: fixCompany(companies.find(({ id }) => id === obj.company.id)),
});
return await CompanyEventsService.listEventsForCompany(id, type);
}, ({ params }) => {
const { type, id } = params;

return `${ type }::${ id }`;
}));

router.get("/info/:id", cachedFetcher(cacheForMs, async ({ params }) => {
const { data } = await internalRequest("GET", "/companies/events/all") || {};
const { companies, ...rawEvents } = data;

const company = companies.find(({ id }) => String(id) === String(params.id));

if (!company) {
throw new ApiError("Company not found", HttpStatus.Error.Client.NotFound);
}
const { id } = params;

const newType = (key) => {
switch (key) {
case "presentations":
return "talk";
case "workshops":
return "workshop";
default:
return key.replace(/s$/, "");
}
};

const events =
Object
.entries(rawEvents)
.flatMap(
([ type, events ]) =>
events.map(
(event) =>
Object.assign(
event,
{
type: newType(type),
title: event.title || event.name,
topic: event.topic || "Workshop",
},
),
),
)
.filter(({ company, companies }) => {
if (String(company.id) === String(params.id)) {
return true;
}

if (!companies) {
return false;
}

return companies.find(({ info }) => String(info.id) === String(params.id));
})
;

return { ...company, events };
return await CompanyService.fetchInfo(id);
}, ({ params }) => {
return params.id;
}));

router.post("/vat/check", async ({ body }) => {
const { vat } = body;

if (!vat) {
throw new ApiError("no-vat", HttpStatus.Error.Client.UnprocessableEntity);
}

return await VatValidator.validate(vat);
});

router.post("/vat/info/existing", async ({ body }) => {
const { vat } = body;

if (!vat) {
throw new ApiError("no-vat", HttpStatus.Error.Client.UnprocessableEntity);
}

return await CompanyService.fetchInfoFromVat(vat);
});

router.post("/vat/info/remote", async ({ body }) => {
const { vat } = body;

if (!vat) {
throw new ApiError("no-vat", HttpStatus.Error.Client.UnprocessableEntity);
}

return await VatValidator.remoteInfo(vat);
});

router.post("/vat/info/any", async ({ body }) => {
const { vat } = body;

if (!vat) {
throw new ApiError("no-vat", HttpStatus.Error.Client.UnprocessableEntity);
}

try {
return await CompanyService.fetchInfoFromVat(vat);
} catch {
}

return await VatValidator.remoteInfo(vat);
});

export default router;
Loading

0 comments on commit 96fc936

Please sign in to comment.