diff --git a/src/Type_Definitions/Contest_Contest.js b/src/Type_Definitions/Contest_Contest.js index 0d9abed..1fb93a5 100644 --- a/src/Type_Definitions/Contest_Contest.js +++ b/src/Type_Definitions/Contest_Contest.js @@ -11,6 +11,7 @@ const contestDefs = gql` ): PostConnection! # getTopContestPosts(contestId: String, top: Int!): [Post]! getTopContestPosts(data: ContestInfoInput!): [Post]! + getUserPrizes(data: UserPrizeInput!): [Contest_Prize]! # getContestPrizes # getPrizes # getContestPostScore @@ -79,6 +80,10 @@ const contestDefs = gql` contestId: ID! } + input UserPrizeInput { + userId: ID! + } + type Contest { id: ID! name: String! diff --git a/src/index.js b/src/index.js index 9a062f9..35e89a5 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,6 @@ // Apollo import { ApolloServer } from '@apollo/server'; -import { startStandaloneServer } from '@apollo/server/standalone'; +// import { startStandaloneServer } from '@apollo/server/standalone'; import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default'; diff --git a/src/resolvers/Mutation/contest.js b/src/resolvers/Mutation/contest.js index 58dc994..689135c 100644 --- a/src/resolvers/Mutation/contest.js +++ b/src/resolvers/Mutation/contest.js @@ -52,10 +52,11 @@ const contestMutation = { isFinished: true, }, }); + console.log({ result }); - const users = await prisma.post.findMany({ + const top3 = await prisma.post.findMany({ where: { - contestId: contestId, + contestId, }, orderBy: [ { points: 'desc' }, @@ -65,19 +66,49 @@ const contestMutation = { ], take: 3, include: { - userId: { - id: true, - }, + post_to_user: { select: { id: true } }, }, }); - console.log({ users }); + console.log({ top3 }); + // console.log(top3[0]); - // await prisma.contest_Prize.create({ - // data: { - // contestId: contestId, - // }, - // }); + const a = await prisma.contest_Prize.createMany({ + data: [ + { + contestId, + userId: top3[0] + ? top3[0].post_to_user.id + : '000000000000000000000000', + title: 'First place ' + result.name, + type: 'First', + prizeImageURL: + 'https://bku-profile-pic.s3.ap-southeast-1.amazonaws.com/1.png', + }, + { + contestId, + userId: top3[1] + ? top3[1].post_to_user.id + : '000000000000000000000000', + title: 'Second place ' + result.name, + type: 'Second', + prizeImageURL: + 'https://bku-profile-pic.s3.ap-southeast-1.amazonaws.com/2.png', + }, + { + contestId, + userId: top3[2] + ? top3[2].post_to_user.id + : '000000000000000000000000', + title: 'Third place ' + result.name, + type: 'Third', + prizeImageURL: + 'https://bku-profile-pic.s3.ap-southeast-1.amazonaws.com/3.png', + }, + ], + }); + + console.log({ a }); return result; }, @@ -97,7 +128,6 @@ const contestMutation = { return result; }, - joinContest: async (parent, args, info) => { let result; try { diff --git a/src/resolvers/Query/CONTEST.js b/src/resolvers/Query/CONTEST.js index 0f9a049..2e80808 100644 --- a/src/resolvers/Query/CONTEST.js +++ b/src/resolvers/Query/CONTEST.js @@ -113,6 +113,13 @@ const contestQuery = { take: 5, }); }, + getUserPrizes: async (parent, args, info) => { + return await prisma.contest_Prize.findMany({ + where: { + userId: args.data.userId, + }, + }); + }, }; export default contestQuery; diff --git a/src/resolvers/Query/POST.js b/src/resolvers/Query/POST.js index 6fe59b9..fa74faa 100644 --- a/src/resolvers/Query/POST.js +++ b/src/resolvers/Query/POST.js @@ -38,6 +38,7 @@ const postQuery = { a = await prisma.post.findMany({ where: { userId: userId, + contestId: '', categoryId: { hasEvery: categoryIds, }, @@ -84,6 +85,7 @@ const postQuery = { if (timeCall % 2 === 1) { a = await prisma.post.findMany({ where: { + contestId: '', AND: [ { userId: { in: b.userFollowing } }, { @@ -138,6 +140,7 @@ const postQuery = { ], userId: { notIn: b.userFollowing }, postViewStatus: 'PUBLIC', + contestId: '', categoryId: { hasEvery: categoryIds, }, diff --git a/src/resolvers/Type/ContestPrize___.js b/src/resolvers/Type/ContestPrize___.js index 05f169c..4441e37 100644 --- a/src/resolvers/Type/ContestPrize___.js +++ b/src/resolvers/Type/ContestPrize___.js @@ -2,14 +2,14 @@ import { prisma } from '../../prisma/database.js'; const Contest_Prize = { contestId: async (parent, args, info) => { - return await prisma.contest.findMany({ + return await prisma.contest.findUnique({ where: { id: parent.contestId, }, }); }, userId: async (parent, args, info) => { - return await prisma.user.findMany({ + return await prisma.user.findUnique({ where: { id: parent.userId, },