-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
136 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |