From bf3325437fddc7e354084e411a0e91bb3baba43f Mon Sep 17 00:00:00 2001 From: potts99 Date: Sat, 25 Nov 2023 21:47:52 +0000 Subject: [PATCH 1/4] docker --- apps/api/src/main.ts | 2 ++ apps/client/package.json | 4 +--- apps/client/pages/auth/login.tsx | 2 +- apps/client/prisma/prisma.js | 2 -- docker-compose.dev.yml | 2 +- docker-compose.local.yml | 4 ++-- docker-compose.yml | 2 +- dockerfile | 7 ++++--- ecosystem.config.js | 1 + 9 files changed, 13 insertions(+), 13 deletions(-) delete mode 100644 apps/client/prisma/prisma.js diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 0f22f38c1..bc4861bc9 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -29,6 +29,7 @@ server.register(require("@fastify/swagger"), { url: "https://swagger.io", description: "Find more info here", }, + mode: "static", host: "localhost", schemes: ["http"], consumes: ["application/json"], @@ -37,6 +38,7 @@ server.register(require("@fastify/swagger"), { { name: "user", description: "User related end-points" }, { name: "code", description: "Code related end-points" }, ], + exposeRoute: true, definitions: { User: { type: "object", diff --git a/apps/client/package.json b/apps/client/package.json index 4babf918f..11ad3bb07 100644 --- a/apps/client/package.json +++ b/apps/client/package.json @@ -5,9 +5,7 @@ "scripts": { "dev": "next dev", "build": "next build", - "start": "next start", - "docker": "yarn run migrate && yarn run generate && yarn run seed && yarn start", - "pm2-prod": "yarn run migrate && yarn run generate && yarn run seed && yarn run build && pm2 start npm --name \"next\" -- start" + "start": "next start" }, "dependencies": { "@headlessui/react": "^1.4.2", diff --git a/apps/client/pages/auth/login.tsx b/apps/client/pages/auth/login.tsx index 2fd297986..623581a91 100644 --- a/apps/client/pages/auth/login.tsx +++ b/apps/client/pages/auth/login.tsx @@ -14,7 +14,7 @@ export default function Login({}) { const { setUser } = useUser(); async function postData() { - await fetch("http://localhost:5003/api/v1/auth/login", { + await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/auth/login`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, password }), diff --git a/apps/client/prisma/prisma.js b/apps/client/prisma/prisma.js deleted file mode 100644 index 2b349b84b..000000000 --- a/apps/client/prisma/prisma.js +++ /dev/null @@ -1,2 +0,0 @@ -import { PrismaClient } from 'database'; -export const prisma = new PrismaClient(); diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index be2a4b060..50031815a 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -32,7 +32,7 @@ services: DB_USERNAME: "peppermint" DB_PASSWORD: "1234" DB_HOST: "peppermint_postgres" - API_PORT: 5003 + API_URL: "http://localhost:5003" volumes: pgdata: \ No newline at end of file diff --git a/docker-compose.local.yml b/docker-compose.local.yml index 4a6a76865..3d99c4769 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -32,7 +32,7 @@ services: DB_USERNAME: "peppermint" DB_PASSWORD: "1234" DB_HOST: "peppermint_postgres" - API_PORT: 5003 - + API_URL: "http://localhost:5003" + volumes: pgdata: \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 0ff3b8ae6..64ff7be46 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,7 +32,7 @@ services: DB_USERNAME: "peppermint" DB_PASSWORD: "1234" DB_HOST: "peppermint_postgres" - API_PORT: 5003 + API_URL: "http://localhost:5003" volumes: pgdata: \ No newline at end of file diff --git a/dockerfile b/dockerfile index 65df1d0ae..05b069aa4 100644 --- a/dockerfile +++ b/dockerfile @@ -9,6 +9,8 @@ RUN apt-get update && \ # Copy the package.json and package-lock.json files for both apps COPY apps/api/package*.json ./apps/api/ COPY apps/client/package*.json ./apps/client/ +COPY ./ecosystem.config.js ./ecosystem.config.js + RUN npm i -g prisma RUN npm i -g typescript@latest -g --force @@ -27,8 +29,7 @@ FROM node:lts AS runner COPY --from=builder /app/apps/api/ ./apps/api/ COPY --from=builder /app/apps/client ./apps/client -COPY ./ecosystem.config.js ./ecosystem.config.js - +COPY --from=builder /app/ecosystem.config.js ./ecosystem.config.js # Expose the ports for both apps EXPOSE 3000 5003 @@ -37,5 +38,5 @@ EXPOSE 3000 5003 RUN npm install -g pm2 # Start both apps using PM2 -CMD ["pm2-runtime", "ecosystem.config .js"] +CMD ["pm2-runtime", "ecosystem.config.js"] diff --git a/ecosystem.config.js b/ecosystem.config.js index c58857f8a..6bb8fb8c2 100644 --- a/ecosystem.config.js +++ b/ecosystem.config.js @@ -11,6 +11,7 @@ module.exports = { env: { NODE_ENV: "production", PORT: 3000, // Change this to your desired port + API_URL: process.env.API_URL, }, }, { From ca61342d1120d4f4fd8ff26846dc8e0515bf6892 Mon Sep 17 00:00:00 2001 From: potts99 Date: Sat, 25 Nov 2023 22:58:21 +0000 Subject: [PATCH 2/4] Hidden Ticket --- apps/api/src/controllers/ticket.ts | 35 +++++++++++- .../20231125221631_hidden/migration.sql | 2 + apps/api/src/prisma/schema.prisma | 1 + apps/client/package.json | 1 + apps/client/pages/tickets/[id].tsx | 57 +++++++++++++------ apps/client/store/session.js | 44 +++++++------- ecosystem.config.js | 1 - yarn.lock | 12 ++++ 8 files changed, 113 insertions(+), 40 deletions(-) create mode 100644 apps/api/src/prisma/migrations/20231125221631_hidden/migration.sql diff --git a/apps/api/src/controllers/ticket.ts b/apps/api/src/controllers/ticket.ts index 4cb205f92..f1aeff869 100644 --- a/apps/api/src/controllers/ticket.ts +++ b/apps/api/src/controllers/ticket.ts @@ -153,7 +153,7 @@ export function ticketRoutes(fastify: FastifyInstance) { if (token) { const tickets = await prisma.ticket.findMany({ - where: { isComplete: false }, + where: { isComplete: false, hidden: false }, include: { client: { select: { id: true, name: true, number: true }, @@ -187,7 +187,7 @@ export function ticketRoutes(fastify: FastifyInstance) { const user = await checkSession(bearer); const tickets = await prisma.ticket.findMany({ - where: { isComplete: false, userId: user!.id }, + where: { isComplete: false, userId: user!.id, hidden: false }, include: { client: { select: { id: true, name: true, number: true }, @@ -219,7 +219,7 @@ export function ticketRoutes(fastify: FastifyInstance) { if (token) { const tickets = await prisma.ticket.findMany({ - where: { isComplete: true }, + where: { isComplete: true, hidden: false }, include: { client: { select: { id: true, name: true, number: true }, @@ -254,6 +254,7 @@ export function ticketRoutes(fastify: FastifyInstance) { where: { isComplete: false, assignedTo: null, + hidden: false, }, }); @@ -430,6 +431,34 @@ export function ticketRoutes(fastify: FastifyInstance) { }); } } + + reply.send({ + success: true, + }); + } + ); + + // Hide a ticket + fastify.put( + "/api/v1/ticket/status/hide", + + async (request: FastifyRequest, reply: FastifyReply) => { + const { hidden, id }: any = request.body; + + await prisma.ticket + .update({ + where: { id: id }, + data: { + hidden: hidden, + }, + }) + .then(async (ticket) => { + // await sendTicketStatus(ticket); + }); + + reply.send({ + success: true, + }); } ); diff --git a/apps/api/src/prisma/migrations/20231125221631_hidden/migration.sql b/apps/api/src/prisma/migrations/20231125221631_hidden/migration.sql new file mode 100644 index 000000000..e55b74cb5 --- /dev/null +++ b/apps/api/src/prisma/migrations/20231125221631_hidden/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Ticket" ADD COLUMN "hidden" BOOLEAN NOT NULL DEFAULT false; diff --git a/apps/api/src/prisma/schema.prisma b/apps/api/src/prisma/schema.prisma index dfbd68da1..fa54db79e 100644 --- a/apps/api/src/prisma/schema.prisma +++ b/apps/api/src/prisma/schema.prisma @@ -106,6 +106,7 @@ model Ticket { Number Int @default(autoincrement()) status TicketStatus @default(needs_support) type TicketType @default(support) + hidden Boolean @default(false) TicketFile TicketFile[] Comment Comment[] diff --git a/apps/client/package.json b/apps/client/package.json index 11ad3bb07..8a6fcddc0 100644 --- a/apps/client/package.json +++ b/apps/client/package.json @@ -45,6 +45,7 @@ "next-themes": "^0.0.15", "next-translate": "^1.3.4", "nodemailer": "^6.7.2", + "posthog-js": "^1.93.2", "prosemirror-model": "^1.18.1", "pug": "^3.0.2", "react": "18.2.0", diff --git a/apps/client/pages/tickets/[id].tsx b/apps/client/pages/tickets/[id].tsx index f8f30159f..51fc33ab7 100644 --- a/apps/client/pages/tickets/[id].tsx +++ b/apps/client/pages/tickets/[id].tsx @@ -7,7 +7,6 @@ import { ChevronUpDownIcon, LockClosedIcon, LockOpenIcon, - PencilIcon, } from "@heroicons/react/20/solid"; import { Link, RichTextEditor } from "@mantine/tiptap"; import Highlight from "@tiptap/extension-highlight"; @@ -23,6 +22,7 @@ import renderHTML from "react-render-html"; import SubScript from "@tiptap/extension-subscript"; import Superscript from "@tiptap/extension-superscript"; import { getCookie } from "cookies-next"; +import { useUser } from "../../store/session"; function classNames(...classes: any) { return classes.filter(Boolean).join(" "); @@ -33,6 +33,10 @@ export default function Ticket() { const token = getCookie("session"); + const { user } = useUser(); + + console.log(user); + const fetchTicketById = async () => { const id = router.query.id; const res = await fetch( @@ -113,9 +117,9 @@ export default function Ticket() { async function updateStatus() { await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/api/v1/ticket/update-status`, + `${process.env.NEXT_PUBLIC_API_URL}/api/v1/ticket/status/update`, { - method: "POST", + method: "PUT", headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, @@ -129,6 +133,26 @@ export default function Ticket() { .then((res) => res.json()) .then(() => refetch()); } + + async function hide(hidden) { + await fetch( + `${process.env.NEXT_PUBLIC_API_URL}/api/v1/ticket/status/hide`, + { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + body: JSON.stringify({ + hidden, + id, + }), + } + ) + .then((res) => res.json()) + .then(() => refetch()); + } + async function addComment() { await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/ticket/comment`, { method: "POST", @@ -303,16 +327,23 @@ export default function Ticket() {

+ {user.isAdmin && ( + + )} {!edit ? ( ) : ( @@ -322,12 +353,8 @@ export default function Ticket() { update(); setEdit(false); }} - className="inline-flex justify-center gap-x-1.5 rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50" + className="inline-flex justify-center gap-x-1.5 rounded-md bg-white px-5 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50" > -