Skip to content

Commit

Permalink
move to proper files
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadPCh committed Oct 15, 2024
1 parent 6908b75 commit f9a1c1c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
16 changes: 16 additions & 0 deletions src/server-extension/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { EProjectSort } from "./types";

export const getProjectSortBy = (sortBy: EProjectSort) => {
switch (sortBy) {
case EProjectSort.HIGHEST_VOUCH_COUNT:
return { sortBy: "vouch", order: "DESC" };
case EProjectSort.LOWEST_VOUCH_COUNT:
return { sortBy: "vouch", order: "ASC" };
case EProjectSort.HIGHEST_FLAG:
return { sortBy: "flag", order: "DESC" };
case EProjectSort.LOWEST_FLAG:
return { sortBy: "flag", order: "ASC" };
default:
return { sortBy: "vouch", order: "DESC" };
}
};
27 changes: 3 additions & 24 deletions src/server-extension/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,8 @@ import "reflect-metadata";
import { GraphQLResolveInfo } from "graphql";
import { Arg, Info, Query, Resolver } from "type-graphql";
import type { EntityManager } from "typeorm";
import { ProjectsSortedByVouchOrFlagType } from "./types"; // Custom ProjectType

enum EProjectSort {
HIGHEST_VOUCH_COUNT = "totalVouches_DESC",
LOWEST_VOUCH_COUNT = "totalVouches_ASC",
HIGHEST_FLAG = "totalFlags_DESC",
LOWEST_FLAG = "totalFlags_ASC",
}

const getSortBy = (sortBy: EProjectSort) => {
switch (sortBy) {
case EProjectSort.HIGHEST_VOUCH_COUNT:
return { sortBy: "vouch", order: "DESC" };
case EProjectSort.LOWEST_VOUCH_COUNT:
return { sortBy: "vouch", order: "ASC" };
case EProjectSort.HIGHEST_FLAG:
return { sortBy: "flag", order: "DESC" };
case EProjectSort.LOWEST_FLAG:
return { sortBy: "flag", order: "ASC" };
default:
return { sortBy: "vouch", order: "DESC" };
}
};
import { EProjectSort, ProjectsSortedByVouchOrFlagType } from "./types"; // Custom ProjectType
import { getProjectSortBy } from "./helper";

@Resolver()
export class ProjectResolver {
Expand All @@ -41,7 +20,7 @@ export class ProjectResolver {
try {
const manager = await this.tx();

const sortInfo = getSortBy(sortBy);
const sortInfo = getProjectSortBy(sortBy);

const vouchValue = sortInfo.sortBy === "vouch";

Expand Down
6 changes: 6 additions & 0 deletions src/server-extension/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Field, ObjectType, ID, Int } from "type-graphql";

export enum EProjectSort {
HIGHEST_VOUCH_COUNT = "totalVouches_DESC",
LOWEST_VOUCH_COUNT = "totalVouches_ASC",
HIGHEST_FLAG = "totalFlags_DESC",
LOWEST_FLAG = "totalFlags_ASC",
}
@ObjectType()
export class ProjectsSortedByVouchOrFlagType {
@Field(() => ID)
Expand Down

0 comments on commit f9a1c1c

Please sign in to comment.