Skip to content

Commit

Permalink
🔨 docker fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Oct 10, 2021
1 parent 1aafeec commit a8bf0bd
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 78 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/middlewares/IsAuth.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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,
},
});

Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`],
Expand Down
112 changes: 57 additions & 55 deletions packages/client/src/components/citizen/ViolationsCard.tsx
Original file line number Diff line number Diff line change
@@ -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<Weapon[]>(props.weapons);
const [tempValue, setTempValue] = React.useState<Weapon | null>(null);
// const [violations, setViolations] = React.useState<Weapon[]>(props.weapons);
// const [tempValue, setTempValue] = React.useState<Weapon | null>(null);

function handleViewClick(weapon: Weapon) {
setTempValue(weapon);
}
// function handleViewClick(weapon: Weapon) {
// setTempValue(weapon);
// }

return (
<>
<div className="bg-gray-200/60 p-4 rounded-md">
<header className="flex items-center justify-between">
<h1 className="text-2xl font-semibold">{t("violations")}</h1>
</header>
// return (
// <>
// <div className="bg-gray-200/60 p-4 rounded-md">
// <header className="flex items-center justify-between">
// <h1 className="text-2xl font-semibold">{t("violations")}</h1>
// </header>

{violations.length <= 0 ? (
<p className="text-gray-600">{t("noViolations")}</p>
) : (
<div className="overflow-x-auto w-full">
<table className="table-auto max-h-64 mt-3">
<thead>
<tr>
<th>{common("type")}</th>
<th>{t("registrationStatus")}</th>
<th>{common("actions")}</th>
</tr>
</thead>
<tbody>
{violations.map((weapon) => (
<tr key={weapon.id}>
<td>{weapon.model}</td>
<td>{weapon.registrationStatus}</td>
<td className="w-[30%]">
<Button onClick={() => handleViewClick(weapon)} small>
{common("view")}
</Button>
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
</>
);
};
// {violations.length <= 0 ? (
// <p className="text-gray-600">{t("noViolations")}</p>
// ) : (
// <div className="overflow-x-auto w-full">
// <table className="table-auto max-h-64 mt-3">
// <thead>
// <tr>
// <th>{common("type")}</th>
// <th>{t("registrationStatus")}</th>
// <th>{common("actions")}</th>
// </tr>
// </thead>
// <tbody>
// {violations.map((weapon) => (
// <tr key={weapon.id}>
// <td>{weapon.model}</td>
// <td>{weapon.registrationStatus}</td>
// <td className="w-[30%]">
// <Button onClick={() => handleViewClick(weapon)} small>
// {common("view")}
// </Button>
// </td>
// </tr>
// ))}
// </tbody>
// </table>
// </div>
// )}
// </div>
// </>
// );
// };

export {};
2 changes: 1 addition & 1 deletion packages/client/src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface Options extends AxiosRequestConfig {
}

export function handleRequest<T = any>(path: string, options?: Options): Promise<AxiosResponse<T>> {
const url = "http://localhost:8080/v1";
const url = process.env.NEXT_PUBLIC_PROD_ORIGIN ?? "http://localhost:8080/v1";

return axios({
url: `${url}${path}`,
Expand Down
17 changes: 12 additions & 5 deletions packages/client/src/pages/admin/values/[path].tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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";
Expand All @@ -20,6 +21,8 @@ interface Props {

export default function ValuePath({ values: { type, values: data } }: Props) {
const [values, setValues] = React.useState<Value[]>(data);
const router = useRouter();
const path = (router.query.path as string).toUpperCase();

const [tempValue, setTempValue] = React.useState<Value | null>(null);
const { state, execute } = useFetch();
Expand Down Expand Up @@ -68,7 +71,7 @@ export default function ValuePath({ values: { type, values: data } }: Props) {
}
}, [isOpen]);

if (!type) {
if (!Object.keys(valueType).includes(path)) {
return (
<Layout>
<p>Path not found</p>
Expand Down Expand Up @@ -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: {
Expand Down
18 changes: 5 additions & 13 deletions packages/client/src/pages/citizen/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand All @@ -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<HTMLFormElement>(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,
Expand Down Expand Up @@ -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,
}))}
Expand All @@ -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,
}))}
Expand Down
4 changes: 2 additions & 2 deletions production.docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ services:
- .env
working_dir: /srv/client
depends_on:
- postgres
- api
networks:
- cad_web

Expand All @@ -59,4 +59,4 @@ volumes:

networks:
cad_web:
external: true
driver: bridge

0 comments on commit a8bf0bd

Please sign in to comment.