Skip to content

Commit

Permalink
fix: use active reservations in reservation quota check
Browse files Browse the repository at this point in the history
  • Loading branch information
vincit-matu authored and joonatank committed May 17, 2024
1 parent bd87005 commit 7355b3e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 124 deletions.
1 change: 1 addition & 0 deletions apps/ui/modules/queries/reservationUnit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const RESERVATION_UNIT_PAGE_FRAGMENT = gql`
minReservationDuration
maxReservationDuration
maxReservationsPerUser
numActiveUserReservations
reservationsMinDaysBefore
reservationsMaxDaysBefore
requireReservationHandling
Expand Down
10 changes: 7 additions & 3 deletions apps/ui/pages/reservation-unit/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,14 @@ const ReservationUnit = ({
const isReservationQuotaReached = useMemo(() => {
return (
reservationUnit?.maxReservationsPerUser != null &&
userReservations?.length != null &&
userReservations?.length >= reservationUnit?.maxReservationsPerUser
reservationUnit?.numActiveUserReservations != null &&
reservationUnit?.numActiveUserReservations >=
reservationUnit?.maxReservationsPerUser
);
}, [reservationUnit?.maxReservationsPerUser, userReservations]);
}, [
reservationUnit?.maxReservationsPerUser,
reservationUnit?.numActiveUserReservations,
]);

const shouldDisplayApplicationRoundTimeSlots =
!!activeApplicationRounds?.length;
Expand Down
54 changes: 0 additions & 54 deletions packages/common/types/gql-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -917,59 +917,6 @@ export enum CustomerTypeChoice {
Nonprofit = "NONPROFIT",
}

/** Debugging information for the current query. */
export type DjangoDebug = {
__typename?: "DjangoDebug";
/** Raise exceptions for this API query. */
exceptions?: Maybe<Array<Maybe<DjangoDebugException>>>;
/** Executed SQL queries for this API query. */
sql?: Maybe<Array<Maybe<DjangoDebugSql>>>;
};

/** Represents a single exception raised. */
export type DjangoDebugException = {
__typename?: "DjangoDebugException";
/** The class of the exception */
excType: Scalars["String"]["output"];
/** The message of the exception */
message: Scalars["String"]["output"];
/** The stack trace */
stack: Scalars["String"]["output"];
};

/** Represents a single database query made to a Django managed DB. */
export type DjangoDebugSql = {
__typename?: "DjangoDebugSQL";
/** The Django database alias (e.g. 'default'). */
alias: Scalars["String"]["output"];
/** Duration of this database query in seconds. */
duration: Scalars["Float"]["output"];
/** Postgres connection encoding if available. */
encoding?: Maybe<Scalars["String"]["output"]>;
/** Whether this database query was a SELECT. */
isSelect: Scalars["Boolean"]["output"];
/** Whether this database query took more than 10 seconds. */
isSlow: Scalars["Boolean"]["output"];
/** Postgres isolation level if available. */
isoLevel?: Maybe<Scalars["String"]["output"]>;
/** JSON encoded database query parameters. */
params: Scalars["String"]["output"];
/** The raw SQL of this query, without params. */
rawSql: Scalars["String"]["output"];
/** The actual SQL sent to this database. */
sql?: Maybe<Scalars["String"]["output"]>;
/** Start time of this database query. */
startTime: Scalars["Float"]["output"];
/** Stop time of this database query. */
stopTime: Scalars["Float"]["output"];
/** Postgres transaction ID if available. */
transId?: Maybe<Scalars["String"]["output"]>;
/** Postgres transaction status if available. */
transStatus?: Maybe<Scalars["String"]["output"]>;
/** The type of database being used (e.g. postrgesql, mysql, sqlite). */
vendor: Scalars["String"]["output"];
};

export type EquipmentCategoryCreateMutationInput = {
name: Scalars["String"]["input"];
nameEn?: InputMaybe<Scalars["String"]["input"]>;
Expand Down Expand Up @@ -1942,7 +1889,6 @@ export enum QualifierOrderingChoices {

export type Query = {
__typename?: "Query";
_debug?: Maybe<DjangoDebug>;
/**
* Return all allocations that affect allocations for given reservation unit
* (through space hierarchy or common resource) during the given time period.
Expand Down
67 changes: 0 additions & 67 deletions tilavaraus.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -866,72 +866,6 @@ scalar DateTime
"""The `Decimal` scalar type represents a python Decimal."""
scalar Decimal

"""Debugging information for the current query."""
type DjangoDebug {
"""Executed SQL queries for this API query."""
sql: [DjangoDebugSQL]

"""Raise exceptions for this API query."""
exceptions: [DjangoDebugException]
}

"""Represents a single exception raised."""
type DjangoDebugException {
"""The class of the exception"""
excType: String!

"""The message of the exception"""
message: String!

"""The stack trace"""
stack: String!
}

"""Represents a single database query made to a Django managed DB."""
type DjangoDebugSQL {
"""The type of database being used (e.g. postrgesql, mysql, sqlite)."""
vendor: String!

"""The Django database alias (e.g. 'default')."""
alias: String!

"""The actual SQL sent to this database."""
sql: String

"""Duration of this database query in seconds."""
duration: Float!

"""The raw SQL of this query, without params."""
rawSql: String!

"""JSON encoded database query parameters."""
params: String!

"""Start time of this database query."""
startTime: Float!

"""Stop time of this database query."""
stopTime: Float!

"""Whether this database query took more than 10 seconds."""
isSlow: Boolean!

"""Whether this database query was a SELECT."""
isSelect: Boolean!

"""Postgres transaction ID if available."""
transId: String

"""Postgres transaction status if available."""
transStatus: String

"""Postgres isolation level if available."""
isoLevel: String

"""Postgres connection encoding if available."""
encoding: String
}

"""Represents a DurationField value as an integer in seconds."""
scalar Duration

Expand Down Expand Up @@ -2278,7 +2212,6 @@ type Query {
orderBy: [BannerNotificationOrderingChoices]
): BannerNotificationNodeConnection
serviceSectors(first: Int, last: Int, offset: Int, after: String, before: String): ServiceSectorNodeConnection
_debug: DjangoDebug
}

input RecurringReservationCreateMutationInput {
Expand Down

0 comments on commit 7355b3e

Please sign in to comment.