Skip to content

Commit

Permalink
Merge pull request #1262 from Shelf-nu/1228-feature-request-reported-…
Browse files Browse the repository at this point in the history
…asset-found

adjustment: change receiver of report found email
  • Loading branch information
DonKoko authored Aug 19, 2024
2 parents 80f6c13 + e68a01f commit 2fa6629
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
8 changes: 4 additions & 4 deletions app/modules/report-found/service.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ export async function createReport({
}

export async function sendReportEmails({
owner,
ownerEmail,
message,
reporterEmail,
qr,
}: {
owner: User;
ownerEmail: User["email"];
message: ReportFound["content"];
reporterEmail: ReportFound["email"];
qr: Prisma.QrGetPayload<{
Expand All @@ -73,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 @@ -93,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
32 changes: 23 additions & 9 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 @@ -45,7 +44,20 @@ export async function action({ request, params }: ActionFunctionArgs) {
id: qrId,
},
include: {
asset: true,
asset: {
include: {
organization: {
select: {
owner: {
select: {
email: true,
id: true,
},
},
},
},
},
},
kit: true,
},
})
Expand Down Expand Up @@ -73,7 +85,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
});
}

const owner = await getUserByID(qr.userId);
const ownerEmail = qr?.asset?.organization?.owner.email;

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

return json(data({ report }));
} catch (cause) {
Expand Down

0 comments on commit 2fa6629

Please sign in to comment.