More events team nonsense
This commit is contained in:
@@ -6,12 +6,11 @@ export async function onRequest(context: RequestContext) {
|
||||
// Skip checks for the by-id endpoint
|
||||
if (pathSegments.length <= 5) return await context.next();
|
||||
|
||||
const eventInfo = await context.env.D1.prepare(
|
||||
"SELECT * FROM events WHERE id = ?;",
|
||||
)
|
||||
.bind(context.params.id)
|
||||
.first();
|
||||
|
||||
const eventInfo = await context.data.prisma.event.findUnique({
|
||||
where: {
|
||||
id: context.params.id as string,
|
||||
},
|
||||
});
|
||||
if (!eventInfo) return jsonError("This event does not exist.", 404);
|
||||
|
||||
if (![1 << 4, 1 << 12].find((p) => context.data.current_user.permissions & p))
|
||||
|
||||
@@ -10,7 +10,7 @@ export async function onRequestPost(context: RequestContext) {
|
||||
try {
|
||||
await D1.batch([
|
||||
D1.prepare(
|
||||
"UPDATE events SET reached_minimum_player_count = 1 WHERE id = ?",
|
||||
"UPDATE events SET reached_minimum_player_count = TRUE WHERE id = ?",
|
||||
).bind(event.id),
|
||||
D1.prepare(
|
||||
"UPDATE et_members SET points = points + 10 WHERE id = ?;",
|
||||
|
||||
@@ -5,23 +5,25 @@ export async function onRequestPost(context: RequestContext) {
|
||||
const { event } = context.data;
|
||||
|
||||
try {
|
||||
const completionTimeRow = await D1.prepare(
|
||||
"SELECT performed_at FROM events WHERE id = ?;",
|
||||
)
|
||||
.bind(event.id)
|
||||
.first();
|
||||
const completionTimeRow = await context.data.prisma.event.findUnique({
|
||||
select: {
|
||||
performed_at: true,
|
||||
},
|
||||
where: {
|
||||
id: event.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (typeof completionTimeRow?.performed_at === "number")
|
||||
if (completionTimeRow?.performed_at instanceof Date)
|
||||
return jsonError(
|
||||
"The event is already marked as complete or forgotten",
|
||||
400,
|
||||
);
|
||||
|
||||
await D1.batch([
|
||||
D1.prepare("UPDATE events SET performed_at = ? WHERE id = ?;").bind(
|
||||
Date.now(),
|
||||
event.id,
|
||||
),
|
||||
D1.prepare(
|
||||
"UPDATE events SET performed_at = CURRENT_TIMESTAMP WHERE id = ?;",
|
||||
).bind(Date.now(), event.id),
|
||||
D1.prepare(
|
||||
"UPDATE et_members SET points = points + 10 WHERE id = ?;",
|
||||
).bind(event.created_by),
|
||||
|
||||
@@ -5,12 +5,15 @@ export async function onRequestPost(context: RequestContext) {
|
||||
if (typeof context.data.body.approved !== "boolean")
|
||||
return jsonError("Decision type must be a boolean", 400);
|
||||
|
||||
const updatedEvent: Record<string, number | string> | null =
|
||||
await context.env.D1.prepare(
|
||||
"UPDATE events SET approved = ?, pending = 0 WHERE id = ? RETURNING created_by, day, month, year;",
|
||||
)
|
||||
.bind(Number(context.data.body.approved), context.data.event.id)
|
||||
.first();
|
||||
const updatedEvent = await context.data.prisma.event.update({
|
||||
data: {
|
||||
approved: context.data.body.approved,
|
||||
pending: false,
|
||||
},
|
||||
where: {
|
||||
id: context.data.event.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!updatedEvent) return jsonError("This event does not exist", 404);
|
||||
|
||||
@@ -19,10 +22,14 @@ export async function onRequestPost(context: RequestContext) {
|
||||
type: "json",
|
||||
});
|
||||
|
||||
const usernameData: Record<string, string> | null =
|
||||
await context.env.D1.prepare("SELECT name FROM et_members WHERE id = ?;")
|
||||
.bind(updatedEvent.created_by)
|
||||
.first();
|
||||
const usernameData = await context.data.prisma.etMember.findUnique({
|
||||
where: {
|
||||
id: updatedEvent.created_by,
|
||||
},
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (emailData && usernameData) {
|
||||
await sendEmail(
|
||||
|
||||
@@ -2,22 +2,25 @@ import { jsonError } from "../../../../common.js";
|
||||
|
||||
export async function onRequestPost(context: RequestContext) {
|
||||
const { D1 } = context.env;
|
||||
const { event } = context.data;
|
||||
const { event, prisma } = context.data;
|
||||
|
||||
try {
|
||||
const row = await D1.prepare(
|
||||
"SELECT performed_at FROM events WHERE id = ?;",
|
||||
)
|
||||
.bind(event.id)
|
||||
.first();
|
||||
const row = await prisma.event.findUnique({
|
||||
select: {
|
||||
performed_at: true,
|
||||
},
|
||||
where: {
|
||||
id: event.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (typeof row?.performed_at === "number")
|
||||
if (row?.performed_at instanceof Date)
|
||||
return jsonError("Event already marked as completed or forgotten", 400);
|
||||
|
||||
await D1.batch([
|
||||
D1.prepare("UPDATE events SET performed_at = 0 WHERE id = ?;").bind(
|
||||
event.id,
|
||||
),
|
||||
D1.prepare(
|
||||
"UPDATE events SET performed_at = datetime(0, 'unixepoch') WHERE id = ?;",
|
||||
).bind(event.id),
|
||||
D1.prepare(
|
||||
"UPDATE et_members SET points = points - 5 WHERE id = ?;",
|
||||
).bind(event.created_by),
|
||||
|
||||
Reference in New Issue
Block a user