From a8bf0bdec1750bb69e028b411a4520462c41758b Mon Sep 17 00:00:00 2001 From: Dev-CasperTheGhost <53900565+Dev-CasperTheGhost@users.noreply.github.com> Date: Sun, 10 Oct 2021 14:01:16 +0200 Subject: [PATCH] :hammer: docker fixes --- .env.example | 3 + packages/api/package.json | 1 + packages/api/src/main.ts | 4 +- packages/api/src/middlewares/IsAuth.ts | 4 + packages/api/src/server.ts | 4 + .../src/components/citizen/ViolationsCard.tsx | 112 +++++++++--------- packages/client/src/lib/fetch.ts | 2 +- .../client/src/pages/admin/values/[path].tsx | 17 ++- packages/client/src/pages/citizen/create.tsx | 18 +-- production.docker-compose.yml | 4 +- 10 files changed, 91 insertions(+), 78 deletions(-) diff --git a/.env.example b/.env.example index 29836c96c..1804ae8c5 100644 --- a/.env.example +++ b/.env.example @@ -11,3 +11,6 @@ DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOST}:${DB_ CORS_ORIGIN_URL="http://localhost:3000" JWT_SECRET="some-random-string-of-characters" + +# keep as is when using docker. +NEXT_PUBLIC_PROD_ORIGIN="http://api:8080/v1" diff --git a/packages/api/package.json b/packages/api/package.json index e0884a78c..95a4c8206 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -3,6 +3,7 @@ "version": "0.0.0", "scripts": { "dev": "prisma migrate dev && prisma generate && nodemon --watch \"src/**/*.ts\" --ignore \"node_modules/**/*\" --exec ts-node src/main.ts", + "start": "prisma migrate deploy && prisma generate && ts-node src/main.ts", "format": "prisma format", "generate": "prisma generate" }, diff --git a/packages/api/src/main.ts b/packages/api/src/main.ts index e710b5e0d..93e6e1678 100644 --- a/packages/api/src/main.ts +++ b/packages/api/src/main.ts @@ -4,11 +4,11 @@ import { Server } from "./server"; async function bootstrap() { try { - $log.debug("Start server..."); + $log.debug("Starting server..."); const platform = await PlatformExpress.bootstrap(Server); await platform.listen(); - $log.debug("Server initialized"); + console.info("SnailyCADv4 is running"); } catch (er) { $log.error(er); } diff --git a/packages/api/src/middlewares/IsAuth.ts b/packages/api/src/middlewares/IsAuth.ts index 525c51d6e..8b63de9b0 100644 --- a/packages/api/src/middlewares/IsAuth.ts +++ b/packages/api/src/middlewares/IsAuth.ts @@ -1,3 +1,4 @@ +import { Rank } from ".prisma/client"; import { Context, Middleware, Req, MiddlewareMethods } from "@tsed/common"; import { getSessionUser } from "../lib/auth"; import { prisma } from "../lib/prisma"; @@ -15,6 +16,9 @@ export class IsAuth implements MiddlewareMethods { towWhitelisted: true, whitelisted: true, // features: true, + liveMapSocketURl: user.rank === Rank.OWNER, + registrationCode: user.rank === Rank.OWNER, + steamApiKey: user.rank === Rank.OWNER, }, }); diff --git a/packages/api/src/server.ts b/packages/api/src/server.ts index abb58f3db..a0eddb484 100644 --- a/packages/api/src/server.ts +++ b/packages/api/src/server.ts @@ -8,6 +8,10 @@ const rootDir = __dirname; @Configuration({ rootDir, + logger: { + debug: true, + level: "off", + }, mount: { "/v1": [`${rootDir}/controllers/**/*.ts`], "/v1/admin/manage": [`${rootDir}/controllers/admin/manage/*.ts`], diff --git a/packages/client/src/components/citizen/ViolationsCard.tsx b/packages/client/src/components/citizen/ViolationsCard.tsx index 7031acc47..629df3f50 100644 --- a/packages/client/src/components/citizen/ViolationsCard.tsx +++ b/packages/client/src/components/citizen/ViolationsCard.tsx @@ -1,60 +1,62 @@ -/* eslint-disable */ -// TODO ^ -import * as React from "react"; -import { Button } from "components/Button"; -import { Weapon } from "types/prisma"; -import { useModal } from "context/ModalContext"; -import { useTranslations } from "use-intl"; -import useFetch from "lib/useFetch"; +// /* eslint-disable */ +// // TODO ^ +// import * as React from "react"; +// import { Button } from "components/Button"; +// import { Weapon } from "types/prisma"; +// import { useModal } from "context/ModalContext"; +// import { useTranslations } from "use-intl"; +// import useFetch from "lib/useFetch"; -export const ViolationsCard = (props: { weapons: Weapon[] }) => { - const { openModal, closeModal } = useModal(); - const common = useTranslations("Common"); - const t = useTranslations("Violations"); +// export const ViolationsCard = (props: { weapons: Weapon[] }) => { +// const { openModal, closeModal } = useModal(); +// const common = useTranslations("Common"); +// const t = useTranslations("Violations"); - const [violations, setViolations] = React.useState(props.weapons); - const [tempValue, setTempValue] = React.useState(null); +// const [violations, setViolations] = React.useState(props.weapons); +// const [tempValue, setTempValue] = React.useState(null); - function handleViewClick(weapon: Weapon) { - setTempValue(weapon); - } +// function handleViewClick(weapon: Weapon) { +// setTempValue(weapon); +// } - return ( - <> -
-
-

{t("violations")}

-
+// return ( +// <> +//
+//
+//

{t("violations")}

+//
- {violations.length <= 0 ? ( -

{t("noViolations")}

- ) : ( -
- - - - - - - - - - {violations.map((weapon) => ( - - - - - - ))} - -
{common("type")}{t("registrationStatus")}{common("actions")}
{weapon.model}{weapon.registrationStatus} - -
-
- )} -
- - ); -}; +// {violations.length <= 0 ? ( +//

{t("noViolations")}

+// ) : ( +//
+// +// +// +// +// +// +// +// +// +// {violations.map((weapon) => ( +// +// +// +// +// +// ))} +// +//
{common("type")}{t("registrationStatus")}{common("actions")}
{weapon.model}{weapon.registrationStatus} +// +//
+//
+// )} +//
+// +// ); +// }; + +export {}; diff --git a/packages/client/src/lib/fetch.ts b/packages/client/src/lib/fetch.ts index 9df8dee34..da06e40ce 100644 --- a/packages/client/src/lib/fetch.ts +++ b/packages/client/src/lib/fetch.ts @@ -9,7 +9,7 @@ interface Options extends AxiosRequestConfig { } export function handleRequest(path: string, options?: Options): Promise> { - const url = "http://localhost:8080/v1"; + const url = process.env.NEXT_PUBLIC_PROD_ORIGIN ?? "http://localhost:8080/v1"; return axios({ url: `${url}${path}`, diff --git a/packages/client/src/pages/admin/values/[path].tsx b/packages/client/src/pages/admin/values/[path].tsx index 23d6a6e71..a643a7320 100644 --- a/packages/client/src/pages/admin/values/[path].tsx +++ b/packages/client/src/pages/admin/values/[path].tsx @@ -1,5 +1,6 @@ import { useTranslations } from "use-intl"; import * as React from "react"; +import { useRouter } from "next/router"; import { Button } from "components/Button"; import { Layout } from "components/Layout"; import { Modal } from "components/modal/Modal"; @@ -8,7 +9,7 @@ import { handleRequest } from "lib/fetch"; import { getTranslations } from "lib/getTranslation"; import { GetServerSideProps } from "next"; import { useModal } from "context/ModalContext"; -import { Value, ValueType } from "types/prisma"; +import { Value, valueType, ValueType } from "types/prisma"; import useFetch from "lib/useFetch"; import { Loader } from "components/Loader"; import { ManageValueModal } from "components/admin/values/ManageValueModal"; @@ -20,6 +21,8 @@ interface Props { export default function ValuePath({ values: { type, values: data } }: Props) { const [values, setValues] = React.useState(data); + const router = useRouter(); + const path = (router.query.path as string).toUpperCase(); const [tempValue, setTempValue] = React.useState(null); const { state, execute } = useFetch(); @@ -68,7 +71,7 @@ export default function ValuePath({ values: { type, values: data } }: Props) { } }, [isOpen]); - if (!type) { + if (!Object.keys(valueType).includes(path)) { return (

Path not found

@@ -163,11 +166,15 @@ export default function ValuePath({ values: { type, values: data } }: Props) { export const getServerSideProps: GetServerSideProps = async ({ locale, req, query }) => { const path = query.path; + const { data: values = [] } = await handleRequest(`/admin/values/${path}`, { headers: req.headers, - }).catch(() => ({ - data: null, - })); + }).catch((e) => { + console.error("ere", e); + return { data: [] }; + }); + + console.log({ values }); return { props: { diff --git a/packages/client/src/pages/citizen/create.tsx b/packages/client/src/pages/citizen/create.tsx index ccb9b9320..eda8d0a4a 100644 --- a/packages/client/src/pages/citizen/create.tsx +++ b/packages/client/src/pages/citizen/create.tsx @@ -19,8 +19,8 @@ import { GetServerSideProps } from "next"; import { getSessionUser } from "lib/auth"; import { getTranslations } from "lib/getTranslation"; import { handleRequest } from "lib/fetch"; -import { Value, ValueType } from "types/prisma"; import { Select } from "components/form/Select"; +import { useValues } from "context/ValuesContext"; const INITIAL_VALUES = { name: "", @@ -36,22 +36,14 @@ const INITIAL_VALUES = { image: null, }; -interface Props { - values: { - type: ValueType; - values: Value[]; - }[]; -} - -export default function CreateCitizen({ values }: Props) { +export default function CreateCitizen() { const { state, execute } = useFetch(); const router = useRouter(); const t = useTranslations("Citizen"); const common = useTranslations("Common"); const formRef = React.useRef(null); - const genders = values.find((v) => v.type === "GENDER")?.values ?? []; - const ethnicities = values.find((v) => v.type === "ETHNICITY")?.values ?? []; + const { genders, ethnicities } = useValues(); async function onSubmit( values: typeof INITIAL_VALUES, @@ -147,7 +139,7 @@ export default function CreateCitizen({ values }: Props) { value={values.gender} onChange={handleChange} hasError={!!errors.gender} - values={genders.map((gender) => ({ + values={genders.values.map((gender) => ({ label: gender.value, value: gender.value, }))} @@ -161,7 +153,7 @@ export default function CreateCitizen({ values }: Props) { value={values.ethnicity} onChange={handleChange} hasError={!!errors.ethnicity} - values={ethnicities.map((ethnicity) => ({ + values={ethnicities.values.map((ethnicity) => ({ label: ethnicity.value, value: ethnicity.value, }))} diff --git a/production.docker-compose.yml b/production.docker-compose.yml index 5a5894a1f..560964c2c 100644 --- a/production.docker-compose.yml +++ b/production.docker-compose.yml @@ -49,7 +49,7 @@ services: - .env working_dir: /srv/client depends_on: - - postgres + - api networks: - cad_web @@ -59,4 +59,4 @@ volumes: networks: cad_web: - external: true + driver: bridge