Skip to content

Commit

Permalink
replyto ticket
Browse files Browse the repository at this point in the history
  • Loading branch information
potts99 committed Dec 3, 2023
1 parent 93132da commit 530edf5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 27 deletions.
56 changes: 33 additions & 23 deletions apps/api/src/lib/imap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,29 +87,39 @@ export const getEmails = async () => {

const parsedData = parseEmailContent(textAsHtml);

const imap = await client.imap_Email.create({
data: {
from: from.text,
subject: subject ? subject : "No Subject",
body: text ? text : "No Body",
html: html ? html : "",
text: textAsHtml,
},
});

const ticket = await client.ticket.create({
data: {
email: imap.from,
name: imap.from,
title: imap.subject ? imap.subject : "-",
isComplete: Boolean(false),
priority: "Low",
fromImap: Boolean(true),
detail: textAsHtml,
},
});

console.log(imap, ticket);
if (subject.includes("Re:")) {
return await client.comment.create({
data: {
text: text ? text : "No Body",
userId: null,
ticketId: subject.split(" ")[1].split("#")[1],
},
});
} else {
const imap = await client.imap_Email.create({
data: {
from: from.text,
subject: subject ? subject : "No Subject",
body: text ? text : "No Body",
html: html ? html : "",
text: textAsHtml,
},
});

const ticket = await client.ticket.create({
data: {
email: imap.from,
name: imap.from,
title: imap.subject ? imap.subject : "-",
isComplete: Boolean(false),
priority: "Low",
fromImap: Boolean(true),
detail: textAsHtml,
},
});

console.log(imap, ticket);
}
});
});
msg.once("attributes", (attrs: any) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/lib/nodemailer/ticket/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function sendTicketCreate(ticket: any) {

const emails = await prisma.email.findMany();

if (emails.length > 0) {
if (emails.length === 0) {
if (process.env.ENVIRONMENT === "development") {
let testAccount = await nodeMailer.createTestAccount();
mail = nodeMailer.createTransport({
Expand Down
8 changes: 8 additions & 0 deletions apps/api/src/prisma/migrations/20231203164241_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- DropForeignKey
ALTER TABLE "Comment" DROP CONSTRAINT "Comment_userId_fkey";

-- AlterTable
ALTER TABLE "Comment" ALTER COLUMN "userId" DROP NOT NULL;

-- AddForeignKey
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
6 changes: 3 additions & 3 deletions apps/api/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ model Comment {
text String
public Boolean @default(false)
userId String
user User @relation(fields: [userId], references: [id])
userId String?
user User? @relation(fields: [userId], references: [id])
ticketId String
ticket Ticket @relation(fields: [ticketId], references: [id])
ticket Ticket @relation(fields: [ticketId], references: [id])
}

model Client {
Expand Down

0 comments on commit 530edf5

Please sign in to comment.