More events team nonsense
This commit is contained in:
@@ -25,14 +25,13 @@ export async function loader({ context }: { context: RequestContext }) {
|
||||
status: 403,
|
||||
});
|
||||
|
||||
const memberResults = await context.env.D1.prepare(
|
||||
"SELECT id, name FROM et_members;",
|
||||
).all();
|
||||
|
||||
if (!memberResults.success)
|
||||
throw new Response(null, {
|
||||
status: 500,
|
||||
});
|
||||
const { prisma } = context.data;
|
||||
const memberResults = await prisma.etMember.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
});
|
||||
|
||||
const data: {
|
||||
[k: string]: {
|
||||
@@ -45,7 +44,7 @@ export async function loader({ context }: { context: RequestContext }) {
|
||||
};
|
||||
} = {};
|
||||
|
||||
for (const row of memberResults.results as Record<string, string>[]) {
|
||||
for (const row of memberResults) {
|
||||
data[row.id].fotd = 0;
|
||||
data[row.id].gamenight = 0;
|
||||
data[row.id].name = row.name;
|
||||
@@ -53,22 +52,26 @@ export async function loader({ context }: { context: RequestContext }) {
|
||||
data[row.id].qotd = 0;
|
||||
}
|
||||
|
||||
const eventsResult = await context.env.D1.prepare(
|
||||
"SELECT answered_at, created_by, day, month, performed_at, reached_minimum_player_count, type, year FROM events;",
|
||||
).all();
|
||||
const eventsResult = await prisma.event.findMany({
|
||||
select: {
|
||||
answered_at: true,
|
||||
created_by: true,
|
||||
day: true,
|
||||
month: true,
|
||||
performed_at: true,
|
||||
reached_minimum_player_count: true,
|
||||
type: true,
|
||||
year: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!eventsResult.success)
|
||||
throw new Response(null, {
|
||||
status: 500,
|
||||
});
|
||||
|
||||
for (const row of eventsResult.results) {
|
||||
const creator = row.created_by as string;
|
||||
const type = row.type as string;
|
||||
for (const row of eventsResult) {
|
||||
const creator = row.created_by;
|
||||
const type = row.type;
|
||||
|
||||
if (!data[creator]) continue;
|
||||
|
||||
if (row.performed_at) data[creator][type as string] += 10;
|
||||
if (row.performed_at) data[creator][type] += 10;
|
||||
else {
|
||||
const now = new Date();
|
||||
const currentYear = now.getUTCFullYear();
|
||||
@@ -76,33 +79,17 @@ export async function loader({ context }: { context: RequestContext }) {
|
||||
const currentDay = now.getUTCDate();
|
||||
|
||||
if (
|
||||
(row.year as number) < currentYear ||
|
||||
(currentYear === row.year && currentMonth > (row.month as number)) ||
|
||||
row.year < currentYear ||
|
||||
(currentYear === row.year && currentMonth > row.month) ||
|
||||
(currentMonth === row.month &&
|
||||
currentYear === row.year &&
|
||||
(row.day as number) < currentDay)
|
||||
row.day < currentDay)
|
||||
)
|
||||
data[creator][type] -= 5;
|
||||
}
|
||||
|
||||
switch (row.type) {
|
||||
case "gamenight":
|
||||
if (row.reached_minimum_player_count) data[creator].gamenight += 10;
|
||||
|
||||
break;
|
||||
|
||||
case "rotw":
|
||||
if (
|
||||
(row.answered_at as number) - (row.performed_at as number) >=
|
||||
86400000
|
||||
)
|
||||
data[creator].rotw += 10;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (row.type === "gamenight" && row.reached_minimum_player_count)
|
||||
data[creator].gamenight += 10;
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
Reference in New Issue
Block a user