mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-25 07:32:19 -05:00
PlusVotes db queries to sql files
This commit is contained in:
parent
78578d93bf
commit
294807ce2a
|
|
@ -1,6 +1,6 @@
|
|||
import * as users from "./models/users/users.server";
|
||||
import * as plusSuggestions from "./models/plusSuggestions/queries.server";
|
||||
import * as plusVotes from "./models/plusVotes/plusVotes.server";
|
||||
import * as plusVotes from "./models/plusVotes/queries.server";
|
||||
import * as badges from "./models/badges/queries.server";
|
||||
import * as calendarEvents from "./models/calendar/queries.server";
|
||||
|
||||
|
|
|
|||
20
app/db/models/plusVotes/create.sql
Normal file
20
app/db/models/plusVotes/create.sql
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
insert into
|
||||
"PlusVote" (
|
||||
"month",
|
||||
"year",
|
||||
"tier",
|
||||
"authorId",
|
||||
"votedId",
|
||||
"score",
|
||||
"validAfter"
|
||||
)
|
||||
values
|
||||
(
|
||||
@month,
|
||||
@year,
|
||||
@tier,
|
||||
@authorId,
|
||||
@votedId,
|
||||
@score,
|
||||
@validAfter
|
||||
)
|
||||
6
app/db/models/plusVotes/deleteMany.sql
Normal file
6
app/db/models/plusVotes/deleteMany.sql
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
delete from
|
||||
"PlusVote"
|
||||
where
|
||||
"authorId" = @authorId
|
||||
and "month" = @month
|
||||
and "year" = @year
|
||||
8
app/db/models/plusVotes/hasVoted.sql
Normal file
8
app/db/models/plusVotes/hasVoted.sql
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
select
|
||||
1
|
||||
from
|
||||
"PlusVote"
|
||||
where
|
||||
"authorId" = @userId
|
||||
and "month" = @month
|
||||
and "year" = @year
|
||||
12
app/db/models/plusVotes/plusServerMembers.sql
Normal file
12
app/db/models/plusVotes/plusServerMembers.sql
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
select
|
||||
"User"."id",
|
||||
"User"."discordId",
|
||||
"User"."discordName",
|
||||
"User"."discordDiscriminator",
|
||||
"User"."discordAvatar",
|
||||
"User"."bio"
|
||||
from
|
||||
"User"
|
||||
join "PlusTier" on "User"."id" = "PlusTier"."userId"
|
||||
where
|
||||
"PlusTier"."tier" = @plusTier
|
||||
|
|
@ -15,37 +15,14 @@ import type {
|
|||
} from "../../types";
|
||||
import type { FindVisibleForUserSuggestedUserInfo } from "../plusSuggestions/queries.server";
|
||||
|
||||
const createStm = sql.prepare(`
|
||||
INSERT INTO
|
||||
"PlusVote" (
|
||||
"month",
|
||||
"year",
|
||||
"tier",
|
||||
"authorId",
|
||||
"votedId",
|
||||
"score",
|
||||
"validAfter"
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
$month,
|
||||
$year,
|
||||
$tier,
|
||||
$authorId,
|
||||
$votedId,
|
||||
$score,
|
||||
$validAfter
|
||||
)
|
||||
`);
|
||||
import createSql from "./create.sql";
|
||||
import deleteManySql from "./deleteMany.sql";
|
||||
import resultsByMonthYearSql from "./resultsByMonthYear.sql";
|
||||
import plusServerMembersSql from "./plusServerMembers.sql";
|
||||
import hasVotedSql from "./hasVoted.sql";
|
||||
|
||||
const deleteManyStm = sql.prepare(`
|
||||
DELETE FROM
|
||||
"PlusVote"
|
||||
WHERE
|
||||
"authorId" = $authorId
|
||||
AND "month" = $month
|
||||
AND "year" = $year
|
||||
`);
|
||||
const createStm = sql.prepare(createSql);
|
||||
const deleteManyStm = sql.prepare(deleteManySql);
|
||||
|
||||
export type UpsertManyPlusVotesArgs = (Pick<
|
||||
PlusVote,
|
||||
|
|
@ -70,22 +47,8 @@ export const upsertMany = sql.transaction((votes: UpsertManyPlusVotesArgs) => {
|
|||
|
||||
type PlusVotingResultsByMonthYearDatabaseResult = (PlusVotingResultUser &
|
||||
Pick<PlusVotingResult, "score" | "wasSuggested" | "passedVoting" | "tier">)[];
|
||||
const resultsByMonthYearStm = sql.prepare(`
|
||||
SELECT
|
||||
"PlusVotingResult"."wasSuggested",
|
||||
"PlusVotingResult"."passedVoting",
|
||||
"PlusVotingResult"."tier",
|
||||
"PlusVotingResult".score,
|
||||
"User"."id",
|
||||
"User"."discordAvatar",
|
||||
"User"."discordDiscriminator",
|
||||
"User"."discordName",
|
||||
"User"."discordId"
|
||||
FROM "PlusVotingResult"
|
||||
JOIN "User" ON "PlusVotingResult"."votedId" = "User".id
|
||||
WHERE month = $month AND year = $year
|
||||
ORDER BY "User"."discordName" COLLATE NOCASE ASC
|
||||
`);
|
||||
|
||||
const resultsByMonthYearStm = sql.prepare(resultsByMonthYearSql);
|
||||
|
||||
type PlusVotingResultUser = Pick<
|
||||
User,
|
||||
|
|
@ -173,18 +136,7 @@ function ownScoresFromPlusVotingResults(
|
|||
return result.sort((a, b) => a.tier - b.tier);
|
||||
}
|
||||
|
||||
const plusServerMembersStm = sql.prepare(`
|
||||
SELECT
|
||||
"User"."id",
|
||||
"User"."discordId",
|
||||
"User"."discordName",
|
||||
"User"."discordDiscriminator",
|
||||
"User"."discordAvatar",
|
||||
"User"."bio"
|
||||
FROM "User"
|
||||
JOIN "PlusTier" ON "User"."id" = "PlusTier"."userId"
|
||||
WHERE "PlusTier"."tier" = $plusTier
|
||||
`);
|
||||
const plusServerMembersStm = sql.prepare(plusServerMembersSql);
|
||||
|
||||
export type UsersForVoting = {
|
||||
user: Pick<
|
||||
|
|
@ -250,11 +202,7 @@ export function usersForVoting(
|
|||
return shuffle(result.filter(({ user }) => user.id !== loggedInUser.id));
|
||||
}
|
||||
|
||||
const hasVotedStm = sql.prepare(`
|
||||
SELECT 1
|
||||
FROM "PlusVote"
|
||||
WHERE "authorId" = $userId AND "month" = $month AND "year" = $year
|
||||
`);
|
||||
const hasVotedStm = sql.prepare(hasVotedSql);
|
||||
|
||||
export function hasVoted({
|
||||
month,
|
||||
18
app/db/models/plusVotes/resultsByMonthYear.sql
Normal file
18
app/db/models/plusVotes/resultsByMonthYear.sql
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
select
|
||||
"PlusVotingResult"."wasSuggested",
|
||||
"PlusVotingResult"."passedVoting",
|
||||
"PlusVotingResult"."tier",
|
||||
"PlusVotingResult"."score",
|
||||
"User"."id",
|
||||
"User"."discordAvatar",
|
||||
"User"."discordDiscriminator",
|
||||
"User"."discordName",
|
||||
"User"."discordId"
|
||||
from
|
||||
"PlusVotingResult"
|
||||
join "User" on "PlusVotingResult"."votedId" = "User".id
|
||||
where
|
||||
"PlusVotingResult"."month" = @month
|
||||
and "PlusVotingResult"."year" = @year
|
||||
order by
|
||||
"User"."discordName" collate nocase asc
|
||||
|
|
@ -6,7 +6,7 @@ import {
|
|||
} from "~/modules/plus-server";
|
||||
import { db } from "~/db";
|
||||
import { sql } from "~/db/sql";
|
||||
import type { UpsertManyPlusVotesArgs } from "./models/plusVotes/plusVotes.server";
|
||||
import type { UpsertManyPlusVotesArgs } from "./models/plusVotes/queries.server";
|
||||
import { ADMIN_DISCORD_ID } from "~/constants";
|
||||
import shuffle from "just-shuffle";
|
||||
import { dateToDatabaseTimestamp } from "~/utils/dates";
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import * as React from "react";
|
||||
import invariant from "tiny-invariant";
|
||||
import { PLUS_DOWNVOTE, PLUS_UPVOTE } from "~/constants";
|
||||
import type { UsersForVoting } from "~/db/models/plusVotes/plusVotes.server";
|
||||
import type { UsersForVoting } from "~/db/models/plusVotes/queries.server";
|
||||
import type { User } from "~/db/types";
|
||||
import type { PlusVoteFromFE } from "./types";
|
||||
import { nextNonCompletedVoting } from "./voting-time";
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import { CheckmarkIcon } from "~/components/icons/Checkmark";
|
|||
import { RelativeTime } from "~/components/RelativeTime";
|
||||
import { PLUS_DOWNVOTE, PLUS_UPVOTE } from "~/constants";
|
||||
import { db } from "~/db";
|
||||
import type { UsersForVoting } from "~/db/models/plusVotes/plusVotes.server";
|
||||
import type { UsersForVoting } from "~/db/models/plusVotes/queries.server";
|
||||
import { getUser, requireUser } from "~/modules/auth";
|
||||
import type { PlusVoteFromFE } from "~/modules/plus-server";
|
||||
import {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { json } from "@remix-run/node";
|
|||
import { Link, useLoaderData } from "@remix-run/react";
|
||||
import { lastCompletedVoting } from "~/modules/plus-server";
|
||||
import { db } from "~/db";
|
||||
import type { PlusVotingResultByMonthYear } from "~/db/models/plusVotes/plusVotes.server";
|
||||
import type { PlusVotingResultByMonthYear } from "~/db/models/plusVotes/queries.server";
|
||||
import type { PlusVotingResult } from "~/db/types";
|
||||
import { roundToTwoDecimalPlaces } from "~/utils/number";
|
||||
import { makeTitle } from "~/utils/strings";
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user