Skip to content

Commit

Permalink
slightly changing args the sendReportEmails recieve
Browse files Browse the repository at this point in the history
  • Loading branch information
DonKoko committed Aug 19, 2024
1 parent a4f403f commit e68a01f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
11 changes: 4 additions & 7 deletions app/modules/report-found/service.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,12 @@ export async function createReport({
}

export async function sendReportEmails({
owner,
ownerEmail,
message,
reporterEmail,
qr,
}: {
owner: {
id: string;
email: string;
};
ownerEmail: User["email"];
message: ReportFound["content"];
reporterEmail: ReportFound["email"];
qr: Prisma.QrGetPayload<{
Expand All @@ -76,7 +73,7 @@ export async function sendReportEmails({
return await Promise.all([
/** Send email to owner */
sendEmail({
to: owner.email,
to: ownerEmail,
subject,
text: item
? `Your ${type} ${normalizedName} has been reported found. The reason is: \n\n| ${message} \n\n For contact use this email: ${reporterEmail}\n\nEmail sent via shelf.nu\n\n`
Expand All @@ -96,7 +93,7 @@ export async function sendReportEmails({
throw new ShelfError({
cause,
message: "Failed to send report emails",
additionalData: { owner, reporterEmail, item, type, normalizedName },
additionalData: { ownerEmail, reporterEmail, item, type, normalizedName },
label: "Report",
});
}
Expand Down
7 changes: 3 additions & 4 deletions app/routes/qr+/$qrId_.contact-owner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
createReport,
sendReportEmails,
} from "~/modules/report-found/service.server";
import { getUserByID } from "~/modules/user/service.server";
import { ShelfError, makeShelfError } from "~/utils/error";
import { isFormProcessing } from "~/utils/form";
import {
Expand Down Expand Up @@ -86,7 +85,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
});
}

const owner = qr?.asset?.organization?.owner;
const ownerEmail = qr?.asset?.organization?.owner.email;

const payload = parseData(await request.formData(), NewReportSchema);
const { email, content } = payload;
Expand All @@ -103,9 +102,9 @@ export async function action({ request, params }: ActionFunctionArgs) {
* 1. To the owner of the asset
* 2. To the person who reported the asset as found
*/
if (owner) {
if (ownerEmail) {
await sendReportEmails({
owner: qr?.asset?.organization?.owner as { id: string; email: string },
ownerEmail,
qr,
message: report.content,
reporterEmail: report.email,
Expand Down

0 comments on commit e68a01f

Please sign in to comment.