mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-09 04:02:40 -05:00
Add some max count checks
This commit is contained in:
parent
a2545ce694
commit
e6c6ed097b
|
|
@ -321,6 +321,18 @@ export async function findMutualFriends({
|
|||
.execute();
|
||||
}
|
||||
|
||||
export async function countPendingSentRequests(
|
||||
senderId: number,
|
||||
): Promise<number> {
|
||||
const result = await db
|
||||
.selectFrom("FriendRequest")
|
||||
.select((eb) => eb.fn.countAll<number>().as("count"))
|
||||
.where("FriendRequest.senderId", "=", senderId)
|
||||
.executeTakeFirstOrThrow();
|
||||
|
||||
return result.count;
|
||||
}
|
||||
|
||||
export async function findFriendship({
|
||||
userOneId,
|
||||
userTwoId,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ import type { ActionFunction } from "react-router";
|
|||
import { requireUser } from "~/features/auth/core/user.server";
|
||||
import { notify } from "~/features/notifications/core/notify.server";
|
||||
import { parseFormData } from "~/form/parse.server";
|
||||
import { errorToastIfFalsy } from "~/utils/remix.server";
|
||||
import * as FriendRepository from "../FriendRepository.server";
|
||||
import { FRIEND } from "../friends-constants";
|
||||
import { friendsActionSchema } from "../friends-schemas.server";
|
||||
|
||||
export const action: ActionFunction = async ({ request }) => {
|
||||
|
|
@ -19,6 +21,14 @@ export const action: ActionFunction = async ({ request }) => {
|
|||
|
||||
switch (result.data._action) {
|
||||
case "SEND_REQUEST": {
|
||||
const pendingCount = await FriendRepository.countPendingSentRequests(
|
||||
user.id,
|
||||
);
|
||||
errorToastIfFalsy(
|
||||
pendingCount < FRIEND.MAX_PENDING_REQUESTS,
|
||||
"Maximum pending friend requests reached",
|
||||
);
|
||||
|
||||
await FriendRepository.insertFriendRequest({
|
||||
senderId: user.id,
|
||||
receiverId: result.data.userId,
|
||||
|
|
|
|||
3
app/features/friends/friends-constants.ts
Normal file
3
app/features/friends/friends-constants.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export const FRIEND = {
|
||||
MAX_PENDING_REQUESTS: 20,
|
||||
} as const;
|
||||
|
|
@ -47,6 +47,16 @@ export async function isSaved({
|
|||
return Boolean(row);
|
||||
}
|
||||
|
||||
export async function countByUserId(userId: number): Promise<number> {
|
||||
const result = await db
|
||||
.selectFrom("SavedTournament")
|
||||
.select((eb) => eb.fn.countAll<number>().as("count"))
|
||||
.where("userId", "=", userId)
|
||||
.executeTakeFirstOrThrow();
|
||||
|
||||
return result.count;
|
||||
}
|
||||
|
||||
export async function findTournamentIdsByUserId(
|
||||
userId: number,
|
||||
): Promise<number[]> {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import deleteTeamMember from "../queries/deleteTeamMember.server";
|
|||
import { findOwnTournamentTeam } from "../queries/findOwnTournamentTeam.server";
|
||||
import { joinTeam } from "../queries/joinLeaveTeam.server";
|
||||
import { upsertCounterpickMaps } from "../queries/upsertCounterpickMaps.server";
|
||||
import { TOURNAMENT } from "../tournament-constants";
|
||||
import { registerSchema } from "../tournament-schemas.server";
|
||||
import {
|
||||
isOneModeTournamentOf,
|
||||
|
|
@ -352,6 +353,12 @@ export const action: ActionFunction = async ({ request, params }) => {
|
|||
break;
|
||||
}
|
||||
case "SAVE_TOURNAMENT": {
|
||||
const count = await SavedTournamentRepository.countByUserId(user.id);
|
||||
errorToastIfFalsy(
|
||||
count < TOURNAMENT.MAX_SAVED_COUNT,
|
||||
"Maximum saved tournaments reached",
|
||||
);
|
||||
|
||||
await SavedTournamentRepository.save({ userId: user.id, tournamentId });
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ export const TOURNAMENT = {
|
|||
SWISS_DEFAULT_GROUP_COUNT: 1,
|
||||
SWISS_DEFAULT_ROUND_COUNT: 5,
|
||||
SE_DEFAULT_HAS_THIRD_PLACE_MATCH: true,
|
||||
MAX_SAVED_COUNT: 20,
|
||||
ROUND_NAMES: {
|
||||
WB_FINALS: "WB Finals",
|
||||
GRAND_FINALS: "Grand Finals",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user