refactor: split the makers page into sections & functionalities

This commit is contained in:
MTG2000
2022-09-06 11:29:23 +03:00
parent 939832a7ac
commit 345ef79cdd
13 changed files with 503 additions and 161 deletions

View File

@@ -246,7 +246,6 @@ export interface NexusGenObjects {
id: number; // Int!
judges: NexusGenRootTypes['TournamentJudge'][]; // [TournamentJudge!]!
location: string; // String!
makers_count: number; // Int!
prizes: NexusGenRootTypes['TournamentPrize'][]; // [TournamentPrize!]!
projects_count: number; // Int!
start_date: NexusGenScalars['Date']; // Date!
@@ -274,6 +273,11 @@ export interface NexusGenObjects {
jobTitle: string; // String!
name: string; // String!
}
TournamentMakersResponse: { // root type
hasNext?: boolean | null; // Boolean
hasPrev?: boolean | null; // Boolean
makers: NexusGenRootTypes['User'][]; // [User!]!
}
TournamentPrize: { // root type
amount: string; // String!
image: string; // String!
@@ -487,7 +491,7 @@ export interface NexusGenFieldTypes {
getDonationsStats: NexusGenRootTypes['DonationsStats']; // DonationsStats!
getFeed: NexusGenRootTypes['Post'][]; // [Post!]!
getLnurlDetailsForProject: NexusGenRootTypes['LnurlDetails']; // LnurlDetails!
getMakersInTournament: NexusGenRootTypes['User'][]; // [User!]!
getMakersInTournament: NexusGenRootTypes['TournamentMakersResponse']; // TournamentMakersResponse!
getMyDrafts: NexusGenRootTypes['Post'][]; // [Post!]!
getPostById: NexusGenRootTypes['Post']; // Post!
getProject: NexusGenRootTypes['Project']; // Project!
@@ -577,6 +581,11 @@ export interface NexusGenFieldTypes {
jobTitle: string; // String!
name: string; // String!
}
TournamentMakersResponse: { // field return type
hasNext: boolean | null; // Boolean
hasPrev: boolean | null; // Boolean
makers: NexusGenRootTypes['User'][]; // [User!]!
}
TournamentPrize: { // field return type
amount: string; // String!
image: string; // String!
@@ -813,7 +822,7 @@ export interface NexusGenFieldTypeNames {
getDonationsStats: 'DonationsStats'
getFeed: 'Post'
getLnurlDetailsForProject: 'LnurlDetails'
getMakersInTournament: 'User'
getMakersInTournament: 'TournamentMakersResponse'
getMyDrafts: 'Post'
getPostById: 'Post'
getProject: 'Project'
@@ -903,6 +912,11 @@ export interface NexusGenFieldTypeNames {
jobTitle: 'String'
name: 'String'
}
TournamentMakersResponse: { // field return type name
hasNext: 'Boolean'
hasPrev: 'Boolean'
makers: 'User'
}
TournamentPrize: { // field return type name
amount: 'String'
image: 'String'

View File

@@ -252,7 +252,7 @@ type Query {
getDonationsStats: DonationsStats!
getFeed(skip: Int = 0, sortBy: String, tag: Int = 0, take: Int = 10): [Post!]!
getLnurlDetailsForProject(project_id: Int!): LnurlDetails!
getMakersInTournament(roleId: Int, search: String, skip: Int = 0, take: Int = 10, tournamentId: Int!): [User!]!
getMakersInTournament(roleId: Int, search: String, skip: Int = 0, take: Int = 10, tournamentId: Int!): TournamentMakersResponse!
getMyDrafts(type: POST_TYPE!): [Post!]!
getPostById(id: Int!, type: POST_TYPE!): Post!
getProject(id: Int!): Project!
@@ -374,6 +374,12 @@ type TournamentJudge {
name: String!
}
type TournamentMakersResponse {
hasNext: Boolean
hasPrev: Boolean
makers: [User!]!
}
type TournamentPrize {
amount: String!
image: String!

View File

@@ -79,7 +79,11 @@ const Tournament = objectType({
t.nonNull.string('website');
t.nonNull.int('events_count');
t.nonNull.int('makers_count');
t.nonNull.int('makers_count', {
resolve(parent) {
return prisma.user.count();
}
});
t.nonNull.int('projects_count');
t.nonNull.list.nonNull.field('prizes', { type: TournamentPrize, });
@@ -89,6 +93,29 @@ const Tournament = objectType({
}
})
const TournamentMakersResponse = objectType({
name: 'TournamentMakersResponse',
definition(t) {
t.boolean('hasNext');
t.boolean('hasPrev');
t.nonNull.list.nonNull.field('makers', { type: "User" })
}
}
)
const TournamentProjectsResponse = objectType({
name: 'TournamentProjectsResponse',
definition(t) {
t.boolean('hasNext');
t.boolean('hasPrev');
t.nonNull.list.nonNull.field('projects', { type: "Project" })
}
}
)
const getTournamentById = extendType({
type: "Query",
definition(t) {
@@ -104,18 +131,20 @@ const getTournamentById = extendType({
}
})
const getMakersInTournament = extendType({
type: "Query",
definition(t) {
t.nonNull.list.nonNull.field('getMakersInTournament', {
type: "User",
t.nonNull.field('getMakersInTournament', {
type: TournamentMakersResponse,
args: {
tournamentId: nonNull(intArg()),
...paginationArgs({ take: 10 }),
search: stringArg(),
roleId: intArg(),
},
resolve(_, args) {
async resolve(_, args) {
let filters = [];
@@ -147,15 +176,84 @@ const getMakersInTournament = extendType({
})
return prisma.user.findMany({
const makers = await prisma.user.findMany({
...(filters.length > 0 && {
where: {
AND: filters
}
}),
skip: args.skip,
take: args.take,
take: args.take + 1,
});
return {
hasNext: makers.length === args.take + 1,
hasPrev: args.skip !== 0,
makers: makers.slice(0, args.take)
}
}
})
}
})
const getProjectsInTournament = extendType({
type: "Query",
definition(t) {
t.nonNull.field('getProjectsInTournament', {
type: TournamentProjectsResponse,
args: {
tournamentId: nonNull(intArg()),
...paginationArgs({ take: 10 }),
search: stringArg(),
roleId: intArg(),
},
async resolve(_, args) {
let filters = [];
if (args.search) filters.push({
OR: [
{
title: {
contains: args.search,
mode: 'insensitive'
}
},
{
description: {
contains: args.search,
mode: 'insensitive'
}
}
]
})
// if (args.roleId) filters.push({
// roles: {
// some: {
// roleId: args.roleId
// }
// }
// })
const makers = await prisma.project.findMany({
...(filters.length > 0 && {
where: {
AND: filters
}
}),
skip: args.skip,
take: args.take + 1,
});
return {
hasNext: makers.length === args.take + 1,
hasPrev: args.skip !== 0,
makers: makers.slice(0, args.take)
}
}
})
}