diff --git a/prisma/seed.ts b/prisma/seed.ts index d8f6429..a1b7a18 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -3,176 +3,442 @@ const { PrismaClient } = require("@prisma/client") as { }; const fs = require("fs"); const prisma = new PrismaClient(); -async function main() { - const events = await prisma.event.findMany({ - where: { - published: true, - }, - select: { - name: true, - Branch: { - select: { - name: true, - }, - }, - Teams: { - select: { - attended: true, - _count: true, - confirmed: true, - TeamMembers: { - include: { - User: { - include: { - College: { - select: { - name: true, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }); - let eventData = []; - for (const event of events) { - eventData.push({ - name: event.name, - branch: event.Branch.name, - participation: event.Teams.reduce((acc, team) => { - return acc + (team.attended ? team._count.TeamMembers : 0); - }, 0), - }); - } - console.log(eventData.reduce((acc, event) => acc + event.participation, 0)); - console.log(eventData); -} -async function getRoadies() { - const data = await prisma.event.findMany({ - where: { - id: 26, - }, - include: { - Teams: { - select: { - roundNo: true, - attended: true, - confirmed: true, - TeamMembers: { - include: { - User: { - select: { - id: true, - name: true, - email: true, - }, - }, - }, - }, - }, - }, - }, - }); - console.log(data); +// async function main() { +// const events = await prisma.event.findMany({ +// where: { +// published: true, +// }, +// select: { +// name: true, +// Branch: { +// select: { +// name: true, +// }, +// }, +// Teams: { +// select: { +// attended: true, +// _count: true, +// confirmed: true, +// TeamMembers: { +// include: { +// User: { +// include: { +// College: { +// select: { +// name: true, +// }, +// }, +// }, +// }, +// }, +// }, +// }, +// }, +// }, +// }); +// let eventData = []; +// for (const event of events) { +// eventData.push({ +// name: event.name, +// branch: event.Branch.name, +// participation: event.Teams.reduce((acc, team) => { +// return acc + (team.attended ? team._count.TeamMembers : 0); +// }, 0), +// }); +// } +// console.log(eventData.reduce((acc, event) => acc + event.participation, 0)); +// console.log(eventData); +// } - let filteredRound2 = data.filter((team) => team.Teams[0].roundNo === 2); - fs.writeFileSync("data.json", JSON.stringify(filteredRound2, null, 2)); -} +// async function getRoadies() { +// const data = await prisma.event.findMany({ +// where: { +// id: 26, +// }, +// include: { +// Teams: { +// select: { +// roundNo: true, +// attended: true, +// confirmed: true, +// TeamMembers: { +// include: { +// User: { +// select: { +// id: true, +// name: true, +// email: true, +// }, +// }, +// }, +// }, +// }, +// }, +// }, +// }); +// console.log(data); + +// let filteredRound2 = data.filter((team) => team.Teams[0].roundNo === 2); +// fs.writeFileSync("data.json", JSON.stringify(filteredRound2, null, 2)); +// } + +// getRoadies().finally(() => { +// console.log("done"); +// }); + +// async function getEventsParticipants() { +// let id = 67; +// let event = await prisma.event.findUnique({ +// where: { +// id, +// }, +// include: { +// Teams: { +// select: { +// id: true, +// attended: true, +// confirmed: true, +// TeamMembers: { +// include: { +// User: { +// select: { +// id: true, +// name: true, +// email: true, +// }, +// }, +// }, +// }, +// }, +// }, +// }, +// }); +// if (!event) { +// console.log("Event not found"); +// return; +// } +// let csvready = event.Teams.map((team) => { +// return team.TeamMembers.map((member) => { +// return { +// Name: member.User.name, +// Email: member.User.email, +// teamId: team.id, +// "User Id": member.User.id, +// attended: team.attended, +// confirmed: team.confirmed, +// }; +// }); +// }); +// } + +// async function totalReg() { +// const roadiesParticipants = await prisma.team.findMany({ +// where: { +// eventId: 70, +// }, +// include: { +// TeamMembers: { +// include: { +// User: true, +// }, +// }, +// }, +// }); + +// let colValues = "teamId,teamName,userId,userName,email,phoneNumber"; +// roadiesParticipants.map((team) => { +// team.TeamMembers.map((user, idx) => { +// if (idx === 0) { +// const line = `${team.id},${team.name},${`INC24-${user.User.id +// .toString() +// .padStart(4, "0") +// .toString()}`}, ${user.User.name}, ${user.User.email}, ${ +// user.User.phoneNumber +// }`; +// colValues += "\n" + line; +// } else { +// const line = `,,${`INC24-${user.User.id +// .toString() +// .padStart(4, "0") +// .toString()}`}, ${user.User.name}, ${user.User.email}, ${ +// user.User.phoneNumber +// }`; +// colValues += "\n" + line; +// } +// }); +// }); +// fs.writeFileSync("bgmi.csv", colValues); +// } + +// totalReg().finally(() => { +// console.log("done"); +// }); + +// async function externalCount(){ +// const count = await prisma.user.findMany({ +// where: { +// NOT:{ +// collegeId:1 +// }, +// role:"PARTICIPANT" + +// }, +// select:{ +// id:true, +// name:true, +// email:true, +// phoneNumber:true, +// College:{ +// select:{ +// name:true +// } +// }, +// role:true, +// } + +// }); +// console.log(count.length); +// fs.writeFileSync("external.json", JSON.stringify(count)); +// } -getRoadies().finally(() => { - console.log("done"); -}); +// externalCount().finally(()=>{ +// console.log("external count done") +// }) -async function getEventsParticipants() { - let id = 67; - let event = await prisma.event.findUnique({ + + + +// async function winnerList(){ +// const winner = await prisma.winners.findMany({ +// where:{ +// type:"RUNNER_UP", +// }, +// include:{ +// Team:{ +// include:{ +// TeamMembers:{ +// include:{ +// User:{ +// select:{ +// name:true, +// email:true, +// phoneNumber:true, +// } +// } +// } +// } +// } +// } +// } +// }) +// console.log(winner); +// fs.writeFileSync("winner.json", JSON.stringify(winner)); +// } + +// winnerList().finally(()=>{ +// console.log("Winner List done") +// }) + +// async function internalCount(){ +// const count = await prisma.user.findMany({ +// where: { +// email:{contains:"incridea"}, +// NOT:{ +// role:"USER" +// }, +// }, +// select:{ +// id:true, +// name:true, +// email:true, +// phoneNumber:true, +// College:{ +// select:{ +// name:true +// } +// }, +// role:true, +// } + +// }); +// console.log(count.length); +// fs.writeFileSync("inernalfirstyear.json", JSON.stringify(count)); +// } + +// internalCount().finally(()=>{ +// console.log("internal first year count done") +// }) + + +// async function collegeWiseUserCount(){ +// const count = await prisma.college.findMany({ +// where:{ +// Users:{ +// some:{ +// role: { +// in: ["PARTICIPANT","ORGANIZER","BRANCH_REP"] +// } +// } +// } +// }, +// select:{ +// name:true, +// _count:{ +// select:{ +// Users:true +// } +// } +// } +// }); + +// console.log(count); +// fs.writeFileSync("collegeWiseCount.json", JSON.stringify(count)); +// } + +// collegeWiseUserCount().finally(()=>{ +// console.log("college wise count done") +// }) + +async function participantsListEventWise(){ + const participation = await prisma.team.findMany({ where: { - id, + attended: true, }, include: { - Teams: { - select: { - id: true, - attended: true, - confirmed: true, - TeamMembers: { + TeamMembers: { + include: { + User: { include: { - User: { - select: { - id: true, - name: true, - email: true, - }, - }, + College: true, }, }, }, }, - }, - }); - if (!event) { - console.log("Event not found"); - return; - } - let csvready = event.Teams.map((team) => { - return team.TeamMembers.map((member) => { - return { - Name: member.User.name, - Email: member.User.email, - teamId: team.id, - "User Id": member.User.id, - attended: team.attended, - confirmed: team.confirmed, - }; - }); - }); -} - -async function totalReg() { - const roadiesParticipants = await prisma.team.findMany({ - where: { - eventId: 70, - }, - include: { - TeamMembers: { - include: { - User: true, + Event: { + select: { + name: true, }, }, }, }); - - let colValues = "teamId,teamName,userId,userName,email,phoneNumber"; - roadiesParticipants.map((team) => { - team.TeamMembers.map((user, idx) => { - if (idx === 0) { - const line = `${team.id},${team.name},${`INC24-${user.User.id - .toString() - .padStart(4, "0") - .toString()}`}, ${user.User.name}, ${user.User.email}, ${ - user.User.phoneNumber - }`; - colValues += "\n" + line; - } else { - const line = `,,${`INC24-${user.User.id - .toString() - .padStart(4, "0") - .toString()}`}, ${user.User.name}, ${user.User.email}, ${ - user.User.phoneNumber - }`; - colValues += "\n" + line; - } - }); - }); - fs.writeFileSync("bgmi.csv", colValues); + console.log(participation); + fs.writeFileSync("participants.json", JSON.stringify(participation)); } -totalReg().finally(() => { - console.log("done"); -}); +participantsListEventWise().finally(()=>{ + console.log("participants count done") +}) + +// async function SDITCollegeparticipantsList() { +// const participants = await prisma.user.findMany({ +// where:{ +// collegeId: 48, +// role:"PARTICIPANT", + +// }, +// select:{ +// name:true, +// email:true, +// phoneNumber:true, +// College:{ +// select:{ +// name:true +// } +// }, + +// } +// }) +// console.log(participants.length); +// fs.writeFileSync("participants.json", JSON.stringify(participants)); +// } + +// SDITCollegeparticipantsList().finally(()=>{ +// console.log("participants count done") +// }) + + +// async function getEventsParticipants() { +// const participants = await prisma.user.findMany({ +// where:{ +// collegeId:101, +// role:"PARTICIPANT", +// TeamMembers:{ +// some:{ +// Team:{ +// attended:true +// } +// } +// } +// }, +// select:{ +// name:true, +// email:true, +// College:{ +// select:{ +// name:true +// }, +// }, +// TeamMembers:{ +// select:{ +// Team:{ +// select:{ +// attended:true, +// confirmed:true, +// Event:{ +// select:{ +// name:true +// } +// } +// } +// } +// } +// } +// } +// }) +// console.log(participants.length); +// fs.writeFileSync("participants.json", JSON.stringify(participants)); +// } + +// getEventsParticipants().finally(()=>{ +// console.log("participants count done") +// }) + +// async function getCollegeWiseParticipants() { +// const colleges = await prisma.college.findMany(); +// const collegeCounts = []; +// // Iterate over each college +// for (const college of colleges) { +// // Count the users with role 'PARTICIPANT' for the current college +// const participants = await prisma.user.count({ +// where: { +// collegeId: college.id, +// role: { +// in: ["PARTICIPANT", "ORGANIZER", "BRANCH_REP","ADMIN","JURY",], +// }, +// TeamMembers:{ +// some:{ +// Team:{ +// attended:true +// } +// } +// } +// } +// }); + +// // Log the count for the current college +// console.log(`${college.name}: ${participants}`); +// collegeCounts.push({ +// college: college.name, +// participantCount: participants +// }); +// } +// console.log(collegeCounts); +// fs.writeFileSync('participant_counts.json', JSON.stringify(collegeCounts, null, 2)); -async function g() {} +// } + +// getCollegeWiseParticipants().finally(()=>{ +// console.log("participants count done") +// }) \ No newline at end of file diff --git a/src/certificates.ts b/src/certificates.ts index f9edfe3..9b9ff95 100644 --- a/src/certificates.ts +++ b/src/certificates.ts @@ -134,7 +134,7 @@ import * as nodemailer from "nodemailer"; import htmlToImage from "node-html-to-image"; import { getCount, getUser, updateCount } from "./utils/email"; -let certificateSentSuccess = 1094; +let certificateSentSuccess = 0; let certificateSentError = 0; async function generateCertificate( @@ -143,7 +143,7 @@ async function generateCertificate( eventName: string ): Promise { try { - const templatePath = path.join(__dirname, "certificate.html"); + const templatePath = path.join(__dirname, "templates/certificate.html"); let html = fs.readFileSync(templatePath, "utf-8"); // Replace {{name}} with participant name @@ -165,7 +165,7 @@ async function generateCertificate( let imagePaths: string[] = []; if (Array.isArray(imageBuffer)) { imagePaths = imageBuffer.map((buffer, index) => { - const imagePath = path.join(__dirname, `certificate_${index}.png`); + const imagePath = path.join(__dirname, `src/certificate_${index}.png`); fs.writeFileSync(imagePath, buffer); return imagePath; }); @@ -193,8 +193,8 @@ async function sendEmailWithAttachment( const count = await getCount(); const user = getUser(count); const transporter = nodemailer.createTransport({ - port: 465, host: "smtp.gmail.com", + port: 465, auth: { user: user, pass: process.env.EMAIL_SERVER_PASSWORD as string, @@ -203,7 +203,7 @@ async function sendEmailWithAttachment( // Compose the email const mailOptions = { - from: user, + from: process.env.EMAIL_FROM as string, to: participantEmail, subject: subject, text: text, @@ -224,19 +224,19 @@ const sendCertificate = async ( eventName: string, participantEmail: string ) => { - const emailText = `Hi ${participantName}, + const emailText = `Hi ${participantName}, -Thank you for your active participation in Incridea, held during April 26th-29th at NMAMIT, Nitte. +Thank you for your active participation in Incridea, held from February 22nd-24th at NMAMIT, Nitte. -Your captivating performance aligned perfectly with our theme: 'Tides Of Change', creating ripples of inspiration and change. Let's continue to ignite the creativity and imagination through Incridea in the years to come.❤️ +Your captivating performance perfectly aligned with our theme, 'Dice of Destiny', casting a spell of chance and fortune. Let's continue to embrace the unpredictable twists of creativity and imagination through Incridea in the years to come.❤️ -Please find your Participation Certificate attached herewith. +Please find your participation certificate attached. Warm Regards, Team Incridea -Check out the Official Aftermovie '23 down below 👇 -https://youtu.be/8Veb3u0xEoE +Check out the Official Aftermovie '24 down below 👇 +https://youtu.be/YoWeuaSMytk Find more updates and highlights of the fest on our Instagram page @incridea 👇 https://instagram.com/incridea @@ -277,6 +277,7 @@ async function sendParticipationCertificate() { }, }, }); + // participationData ={ // name: "Participant Name"; // eventName: "Event Name"; @@ -300,7 +301,7 @@ async function sendParticipationCertificate() { (acc, val) => acc.concat(val), [] ); - for (let i = 1094; i < flattenedParticipationData.length; i++) { + for (let i = 0; i < flattenedParticipationData.length; i++) { const participant = flattenedParticipationData[i]; try { await sendCertificate( @@ -332,10 +333,10 @@ async function sendParticipationCertificate() { ); } - // await fs.writeFileSync( - // "./participation.json", - // JSON.stringify(flattenedParticipationData) - // ); + await fs.writeFileSync( + "./participation.json", + JSON.stringify(flattenedParticipationData) + ); } sendParticipationCertificate() diff --git a/src/models/Card/mutation.ts b/src/models/Card/mutation.ts index 15be72d..35a9482 100644 --- a/src/models/Card/mutation.ts +++ b/src/models/Card/mutation.ts @@ -6,6 +6,7 @@ const DayTypeEnum = builder.enumType(DayType, { name: "DayType", }); +//for easter eggs scanned using QR codes around the college for Publcity Committee builder.mutationField("createCard",(t) => t.prismaField({ type:"Card", diff --git a/src/models/Judge/mutation.ts b/src/models/Judge/mutation.ts index 6a10e34..a69b6e8 100644 --- a/src/models/Judge/mutation.ts +++ b/src/models/Judge/mutation.ts @@ -31,7 +31,7 @@ builder.mutationField("createJudge", (t) => } if (!args.email.endsWith("@incridea.in")) throw new Error("Email should end with @incridea.in"); - + //Creates a new judge credential const judge = await ctx.prisma.judge.create({ data: { User: { diff --git a/src/models/Level/mutation.ts b/src/models/Level/mutation.ts index 70540cb..1803968 100644 --- a/src/models/Level/mutation.ts +++ b/src/models/Level/mutation.ts @@ -1,6 +1,7 @@ import { builder } from "../../builder"; //add level +//Levels for custom easter eggs need to be added manually in the database builder.mutationField("addLevel", (t) => t.prismaField({ type: "Level", diff --git a/src/models/PaymentOrder/mutation.ts b/src/models/PaymentOrder/mutation.ts index 6de3a94..7f77370 100644 --- a/src/models/PaymentOrder/mutation.ts +++ b/src/models/PaymentOrder/mutation.ts @@ -65,7 +65,9 @@ builder.mutationField("createPaymentOrder", (t) => }, }); } + //set amount for external colleges let amount = 350; + //set amount for nmamit.in email if (user.email.endsWith("nmamit.in")) { amount = 250; } else { @@ -77,6 +79,7 @@ builder.mutationField("createPaymentOrder", (t) => College: true, }, }); + if (userData?.College?.type === "OTHER") { amount = 150; } @@ -86,6 +89,7 @@ builder.mutationField("createPaymentOrder", (t) => const currency = "INR"; const options = { + //setting the commisison to 2% for the payment gateway amount: (Math.ceil(amount / 0.98) * 100).toString(), currency, payment_capture, diff --git a/src/models/ProniteRegistration/mutation.ts b/src/models/ProniteRegistration/mutation.ts index 27ec6a8..ac70dfc 100644 --- a/src/models/ProniteRegistration/mutation.ts +++ b/src/models/ProniteRegistration/mutation.ts @@ -25,11 +25,14 @@ builder.mutationField("registerPronite", (t) => const authUser = await ctx.user; if (!authUser) throw new Error("Not authenticated"); + // ID of pronite email used for scanning if (authUser.id != 5181) throw new Error("permission denied, wrong account"); if (!["PARTICIPANT", "ORGANIZER", "BRANCH_REP","ADMIN","JURY"].includes(user.role)) { throw new Error("User did not register for the fest"); } + + //set day here for pronite const pronite = await ctx.prisma.proniteRegistration.findUnique({ where: { userId_proniteDay: { @@ -46,6 +49,7 @@ builder.mutationField("registerPronite", (t) => }); throw new Error(`User already registered for pronite at ${date}`); } + //set day here for pronite const createdPronite = await ctx.prisma.proniteRegistration.create({ data: { userId: Number(args.userId), diff --git a/src/templates/certificate.html b/src/templates/certificate.html index d65d2da..032b76d 100644 --- a/src/templates/certificate.html +++ b/src/templates/certificate.html @@ -3,39 +3,48 @@ + Participation Certificate @@ -43,17 +52,44 @@
- THIS IS TO CERTIFY THAT MR/MS - {{name}} OF - {{college}} HAS PARTICIPATED ACTIVELY IN +
THIS IS TO CERTIFY THAT 
+ MR/MS {{name}} OF + {{college}} HAS PARTICIPATED IN {{event}} DURING - + INCRIDEA LOGO - ‘23 HELD ON APRIL 26TH-29TH AT NMAM INSTITUTE OF TECHNOLOGY, NITTE. + /> + + ‘24 HELD BETWEEN FEBRUARY 22nd - 24th AT N.M.A.M. INSTITUTE OF TECHNOLOGY, NITTE.
+ +