Skip to content

Commit

Permalink
feat: createdby
Browse files Browse the repository at this point in the history
  • Loading branch information
potts99 committed May 31, 2024
1 parent 5c2382c commit bf02bda
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
7 changes: 7 additions & 0 deletions apps/api/src/controllers/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function ticketRoutes(fastify: FastifyInstance) {
email,
engineer,
type,
createdBy
}: any = request.body;

const ticket: any = await prisma.ticket.create({
Expand All @@ -46,6 +47,12 @@ export function ticketRoutes(fastify: FastifyInstance) {
priority: priority ? priority : "low",
email,
type: type ? type.toLowerCase() : "support",
createdBy: {
id: createdBy.id,
name: createdBy.name,
role: createdBy.role,
email: createdBy.email
},
client:
company !== undefined
? {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Ticket" ADD COLUMN "createdBy" JSONB;
3 changes: 3 additions & 0 deletions apps/api/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ model Ticket {
status TicketStatus @default(needs_support)
type TicketType @default(support)
hidden Boolean @default(false)
createdBy Json?
TicketFile TicketFile[]
Comment Comment[]
Expand All @@ -102,6 +103,8 @@ model Ticket {
client Client? @relation(fields: [clientId], references: [id])
clientId String?
userId String?
knowledgeBase knowledgeBase[]
notifications notifications[]
}
Expand Down
11 changes: 11 additions & 0 deletions apps/client/pages/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import SubScript from "@tiptap/extension-subscript";
import Superscript from "@tiptap/extension-superscript";
import { getCookie } from "cookies-next";
import { useRouter } from "next/router";
import { useUser } from "../store/session";

function classNames(...classes: any) {
return classes.filter(Boolean).join(" ");
Expand All @@ -36,6 +37,8 @@ export default function CreateTicket() {

const token = getCookie("session");

const { user } = useUser()

const [name, setName] = useState("");
const [company, setCompany] = useState<any>();
const [engineer, setEngineer] = useState<any>();
Expand Down Expand Up @@ -92,6 +95,8 @@ export default function CreateTicket() {
.then((res) => res.json())
.then((res) => {
if (res) {
// TODO: THINK ABOUT AUTO ASSIGN PREFERENCES
// setEngineer(user)
setUsers(res.users);
}
});
Expand All @@ -116,6 +121,12 @@ export default function CreateTicket() {
priority,
engineer,
type: selected.name,
createdBy: {
id: user.id,
name: user.name,
role: user.role,
email: user.email
}
}),
})
.then((res) => res.json())
Expand Down
8 changes: 6 additions & 2 deletions apps/client/pages/ticket/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,14 @@ export default function Ticket() {
</>
) : (
<>
<span>Created by at </span>
<span className="">
{data.ticket.createdBy && (
<>
<span>Created by <strong>{data.ticket.createdBy.name}</strong> at </span>
<span className="">
{moment(data.ticket.createdAt).format("DD/MM/YYYY")}
</span>
</>
)}
</>
)}
</div>
Expand Down

0 comments on commit bf02bda

Please sign in to comment.