Skip to content

Commit

Permalink
fix: remove imports list
Browse files Browse the repository at this point in the history
  • Loading branch information
Gum-Joe committed Nov 4, 2024
1 parent 52edb4f commit 91dc5d9
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 5 deletions.
6 changes: 3 additions & 3 deletions collection/app/(app)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { auth } from "@/auth";
import { getAcademicYear } from "@/lib/config";
import { getAcademicYearsInDB } from "@/lib/crud/academic-year";
import { getImportList } from "@/lib/crud/importCsv";
// import { getImportList } from "@/lib/crud/importCsv";
import { Stack, Title } from "@mantine/core";
import { redirect } from "next/navigation";
import React from "react";
Expand All @@ -18,7 +18,7 @@ export default async function Index() {
const currentAcademicYear = await getAcademicYear();
const academicYears = await getAcademicYearsInDB();

const imports = await getImportList();
// const imports = await getImportList();

return (
<Stack gap="lg">
Expand All @@ -27,7 +27,7 @@ export default async function Index() {
currentAcademicYear={currentAcademicYear}
validAcaemicYears={academicYears}
/>
<ImportsList imports={imports} />
{/* <ImportsList imports={imports} /> */}
</Stack>
);
}
91 changes: 91 additions & 0 deletions collection/emails/getDucks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* Outputs a JSON file with the students who have not collected their merch, for use by the mailmerge tool
* to send a reminder to these people.
*
* Created with co-pilot.
*/
import { PrismaClient } from "@prisma/client";
// Load .env file ".env"
import dotenv from "dotenv";
import fs from "fs/promises";

dotenv.config();

const prisma = new PrismaClient();

interface OutputRecord {
to: string;
name: string;
shortcode: string;
subject: string;
cid: string;
orderid: number;
quantity: number;
}

async function getUncollectedPeople() {
const uncollectedOrders = await prisma.variant.findFirst({
where: {
RootItem: {
name: "Duck T-Shirt (White)",
},
variantName: "S (36\")",
},
include: {
OrderItem: {
include: {
Order: {
include: {
ImperialStudent: true,
},
},
},
},
}
})

const outputRecords: OutputRecord[] = [];

const studentMap = new Map<string, OutputRecord>();

if (!uncollectedOrders) {
console.error("No uncollected orders found");
return;
}

for (const orderItem of uncollectedOrders.OrderItem) {
const student = orderItem.Order.ImperialStudent;
const studentKey = student.email;

if (orderItem.collected) {
console.log(`Skipping ${studentKey} as already collected`);
continue;
}

if (!studentMap.has(studentKey)) {
studentMap.set(studentKey, {
to: student.email,
name: `${student.firstName} ${student.lastName}`,
shortcode: student.shortcode,
//itemsToCollect: [],
subject: `Information about the Duck T-Shirt (Small) you ordered`,
cid: student.cid,
orderid: orderItem.orderId,
quantity: orderItem.quantity,
});
}

}

outputRecords.push(...studentMap.values());

await fs.writeFile("data/duck-refund.json", JSON.stringify(outputRecords, null, 2));
}

getUncollectedPeople()
.catch((e) => {
console.error(e);
})
.finally(async () => {
await prisma.$disconnect();
});
4 changes: 2 additions & 2 deletions collection/emails/getUncollectedPeople.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function getUncollectedPeople() {
name: `${student.firstName} ${student.lastName}`,
shortcode: student.shortcode,
itemsToCollect: [],
subject: "Collect your remaining DoCSoc Summer Merch",
subject: `FINAL CALL: Collect your DoCSoc${student.shortcode.endsWith("24") ? " (Freshers) " : " "}Merchandise`,
});
}

Expand All @@ -78,7 +78,7 @@ async function getUncollectedPeople() {

outputRecords.push(...studentMap.values());

await fs.writeFile("data/reminders.json", JSON.stringify(outputRecords, null, 2));
await fs.writeFile("data/reminders-03.11.24.json", JSON.stringify(outputRecords, null, 2));
}

getUncollectedPeople()
Expand Down
2 changes: 2 additions & 0 deletions collection/emails/run-duck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# docsoc-mailmerge generate nunjucks ./data/duck-refund.json templates/duck.njk --name=duck -s json -o output
docsoc-mailmerge send ./output/duck
2 changes: 2 additions & 0 deletions collection/emails/run-reminder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# docsoc-mailmerge generate nunjucks ./data/reminders-03.11.24.json templates/reminder-final.njk --name=reminder-final -s json -o output
docsoc-mailmerge send ./output/reminder-final
14 changes: 14 additions & 0 deletions collection/emails/templates/duck.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Dear {{ name }} ({{ shortcode }}),

We are writing to you because you recently purchased a Duck T-Shirt (Small) from the Union Shop, and are yet to collect it.

Unfortunately, we must regret to inform you that we do not have enough t-shirts to fulfil your order, due to an error when counting stock.

As such, we are unable to provide you with the t-shirt you ordered. We are very sorry for this mistake, and we will be refunding you the full amount you paid for the t-shirt.

The refund should process in 2 weeks - if not, please let us know.

Our apologies for any inconvenience this might have caused you.

Kind regards,
DoCSoc Committee.
22 changes: 22 additions & 0 deletions collection/emails/templates/reminder-final.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Hi {{ name }},

You are yet to collect the following DoCSoc merchandise that you bought from the Union Shop, either in this academic year or last academic year:
{% for item in itemsToCollect %}
- {{ item.rootitem }} {{ item.variant }} x{{ item.quantity }} {% endfor %}

(note that the above includes freshers' merchandise automatically if you are a 1st year)

Please note that uncollected merch may not be refunded after the last collection.

Please collect your merch at **one of our last collection dates**:
- Monday 4th Nov, 4:15pm-6pm, Huxley 315
- Friday 8th Nov, 3pm-5pm, Huxley 315 (changed from earlier announcement)

**Merchandise will no longer be available for collection after these dates.**

If you are unable to collect your merch, please let us know before the last collection. You can also arrange for a friend to collect your merch on your behalf, so long as you provide us with their shortcode in advance by replying to this email.

If you have already collected your merch, didn’t buy any merch or otherwise believe this email was sent incorrectly, please let us know!

Kind regards,
DoCSoc Committee.

0 comments on commit 91dc5d9

Please sign in to comment.