Skip to content

Commit

Permalink
Wrap up changing all tables to refine
Browse files Browse the repository at this point in the history
  • Loading branch information
jthoward64 committed Jan 8, 2025
1 parent d0905ff commit 1907fc6
Show file tree
Hide file tree
Showing 36 changed files with 1,746 additions and 1,497 deletions.
4 changes: 2 additions & 2 deletions packages/common/lib/api/filtering/Filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export class SomeFilter {
@Field(() => ArrayBooleanFilter, { nullable: true })
arrayBooleanFilter?: ArrayBooleanFilter;

get filter(): SomeFilterType {
static getFilter(some: SomeFilter): SomeFilterType {
const {
nullFilter,
singleStringFilter,
Expand All @@ -305,7 +305,7 @@ export class SomeFilter {
arrayNumberFilter,
arrayDateFilter,
arrayBooleanFilter,
} = this as Partial<typeof this>;
} = some;

return (nullFilter ??
singleStringFilter ??
Expand Down
14 changes: 6 additions & 8 deletions packages/common/lib/api/params/ListMarathonsResponse.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Matches } from "class-validator";
import { GraphQLNonEmptyString } from "graphql-scalars";
import { DateTime } from "luxon";
import { ArgsType, Field, InputType, ObjectType } from "type-graphql";

import type { MarathonYearString } from "../../utility/primitive/SimpleTypes.js";
import { FilteredListQueryArgs } from "../filtering/FilteredListQueryArgs.js";
import { MarathonNode } from "../resources/Marathon.js";
import { DateTimeScalar } from "../scalars/DateTimeISO.js";
import { MarathonYearScalar } from "../scalars/MarathonYear.js";
import {
IsAfterDateTime,
IsBeforeDateTime,
Expand All @@ -22,9 +22,8 @@ export class ListMarathonsResponse extends AbstractGraphQLPaginatedResponse<Mara

@InputType()
export class CreateMarathonInput {
@Matches(/^DB\d{2}$/, { message: "Year must be in the format DByy" })
@Field(() => GraphQLNonEmptyString)
year!: string;
@Field(() => MarathonYearScalar)
year!: MarathonYearString;

@IsBeforeDateTime("endDate")
@Field(() => DateTimeScalar, { nullable: true })
Expand All @@ -37,9 +36,8 @@ export class CreateMarathonInput {

@InputType()
export class SetMarathonInput {
@Matches(/^DB\d{2}$/, { message: "Year must be in the format DByy" })
@Field(() => GraphQLNonEmptyString)
year!: string;
@Field(() => MarathonYearScalar)
year!: MarathonYearString;

@IsBeforeDateTime("endDate")
@Field(() => DateTimeScalar, { nullable: true })
Expand Down
18 changes: 2 additions & 16 deletions packages/common/lib/api/params/SingleTeamResponse.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { GraphQLNonEmptyString } from "graphql-scalars";
import { ArgsType, Field, InputType, Int, ObjectType } from "type-graphql";

import { DbRole } from "../../authorization/structures.js";
import { OptionalToNullable } from "../../utility/primitive/TypeUtils.js";
import { FilteredListQueryArgs } from "../filtering/FilteredListQueryArgs.js";
import { TeamLegacyStatus, TeamNode, TeamType } from "../resources/Team.js";
import { type GlobalId, GlobalIdScalar } from "../scalars/GlobalId.js";
import { AbstractGraphQLPaginatedResponse } from "./ApiResponse.js";
@ObjectType("ListTeamsResponse", {
implements: AbstractGraphQLPaginatedResponse<TeamNode>,
Expand Down Expand Up @@ -65,20 +63,8 @@ export class ListTeamsArgs extends FilteredListQueryArgs("TeamResolver", [
"name",
"type",
"legacyStatus",
"marathonId",
]) {
@Field(() => [TeamType], { nullable: true })
type!: [TeamType] | null;

@Field(() => [TeamLegacyStatus], { nullable: true })
legacyStatus!: [TeamLegacyStatus] | null;

@Field(() => [DbRole], { nullable: true, deprecationReason: "Use type" })
visibility!: [DbRole] | null;

@Field(() => [GlobalIdScalar], { nullable: true })
marathonId!: GlobalId[] | null;
}
"marathonYear",
]) {}

@ObjectType("DbFundsTeamInfo")
export class DbFundsTeamInfo {
Expand Down
6 changes: 4 additions & 2 deletions packages/common/lib/api/resources/Marathon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { DateTimeISOResolver } from "graphql-scalars";
import type { DateTime } from "luxon";
import { Field, ObjectType } from "type-graphql";

import type { MarathonYearString } from "../../utility/primitive/SimpleTypes.js";
import { createNodeClasses, Node } from "../relay.js";
import type { GlobalId } from "../scalars/GlobalId.js";
import { GlobalIdScalar } from "../scalars/GlobalId.js";
import { MarathonYearScalar } from "../scalars/MarathonYear.js";
import { TimestampedResource } from "./Resource.js";

@ObjectType({
Expand All @@ -13,8 +15,8 @@ import { TimestampedResource } from "./Resource.js";
export class MarathonNode extends TimestampedResource implements Node {
@Field(() => GlobalIdScalar)
id!: GlobalId;
@Field(() => String)
year!: string;
@Field(() => MarathonYearScalar)
year!: MarathonYearString;
@Field(() => DateTimeISOResolver, { nullable: true })
startDate?: DateTime | undefined | null;
@Field(() => DateTimeISOResolver, { nullable: true })
Expand Down
1 change: 1 addition & 0 deletions packages/common/lib/api/scalars/DateTimeISO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DateTime } from "luxon";

export const DateTimeScalar = new GraphQLScalarType<DateTime<true>, string>({
name: "LuxonDateTime",
specifiedByURL: "https://datatracker.ietf.org/doc/html/rfc3339",
description: "Cursor custom scalar type",
parseValue(value): DateTime<true> {
if (typeof value === "string") {
Expand Down
52 changes: 52 additions & 0 deletions packages/common/lib/api/scalars/MarathonYear.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { GraphQLScalarType, Kind } from "graphql";

import type { MarathonYearString } from "../../utility/primitive/SimpleTypes.js";

const marathonYearRegex = /^DB\d{2}$/;
function isMarathonYearString(value: string): value is MarathonYearString {
return marathonYearRegex.test(value);
}

export const MarathonYearScalar = new GraphQLScalarType({
name: "MarathonYear",
description: "MarathonYear custom scalar type",
extensions: {},
parseValue(value): MarathonYearString {
if (typeof value === "string") {
if (!isMarathonYearString(value)) {
throw new TypeError(
"MarathonYearScalar can only parse strings that match the pattern DB00"
);
}
return value;
} else {
throw new TypeError("MarathonYearScalar can only parse strings");
}
},
serialize(value): string {
if (typeof value === "string") {
if (!isMarathonYearString(value)) {
throw new TypeError(
"MarathonYearScalar can only serialize strings that match the pattern"
);
}
return value;
} else {
throw new TypeError("MarathonYearScalar can only serialize strings");
}
},
parseLiteral(ast): MarathonYearString {
if (ast.kind === Kind.STRING) {
if (!isMarathonYearString(ast.value)) {
throw new TypeError(
"MarathonYearScalar can only parse literal string values that match the pattern"
);
}
return ast.value;
} else {
throw new TypeError(
"MarathonYearScalar can only parse literal string values"
);
}
},
});
Loading

0 comments on commit 1907fc6

Please sign in to comment.