Skip to content

Commit

Permalink
update contest
Browse files Browse the repository at this point in the history
  • Loading branch information
HUNG-rushb committed Jan 3, 2024
1 parent 1d3cf90 commit 9963f42
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 15 deletions.
5 changes: 5 additions & 0 deletions src/Type_Definitions/Contest_Contest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,6 +80,10 @@ const contestDefs = gql`
contestId: ID!
}
input UserPrizeInput {
userId: ID!
}
type Contest {
id: ID!
name: String!
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
54 changes: 42 additions & 12 deletions src/resolvers/Mutation/contest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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;
},
Expand All @@ -97,7 +128,6 @@ const contestMutation = {

return result;
},

joinContest: async (parent, args, info) => {
let result;
try {
Expand Down
7 changes: 7 additions & 0 deletions src/resolvers/Query/CONTEST.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 3 additions & 0 deletions src/resolvers/Query/POST.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const postQuery = {
a = await prisma.post.findMany({
where: {
userId: userId,
contestId: '',
categoryId: {
hasEvery: categoryIds,
},
Expand Down Expand Up @@ -84,6 +85,7 @@ const postQuery = {
if (timeCall % 2 === 1) {
a = await prisma.post.findMany({
where: {
contestId: '',
AND: [
{ userId: { in: b.userFollowing } },
{
Expand Down Expand Up @@ -138,6 +140,7 @@ const postQuery = {
],
userId: { notIn: b.userFollowing },
postViewStatus: 'PUBLIC',
contestId: '',
categoryId: {
hasEvery: categoryIds,
},
Expand Down
4 changes: 2 additions & 2 deletions src/resolvers/Type/ContestPrize___.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit 9963f42

Please sign in to comment.