Skip to content

Commit

Permalink
feat: add video to tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushalrathi24 committed Feb 3, 2024
2 parents 752f161 + 9f59012 commit c6bf140
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 67 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ jobs:
- name: Build to test
run: npm run build

# Deploy:
# needs: Test
# runs-on: self-hosted
# steps:
# - name: Checkout repository
# uses: actions/checkout@v3
Deploy:
needs: Test
runs-on: self-hosted
steps:
- name: Checkout repository
uses: actions/checkout@v3

# - name: Pull Changes
# run: git pull origin main
# working-directory: /home/aryan/CCS-Backend-2022
- name: Pull Changes
run: git pull origin main
working-directory: /home/aryan/CCS-Backend-2022

# - name: Build and Deploy
# run: |
# sudo docker compose up --build -d
# working-directory: /home/aryan/CCS-Backend-2022
- name: Build and Deploy
run: |
sudo docker compose up --build -d
working-directory: /home/aryan/CCS-Backend-2022
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
FROM node:16.6.2
FROM node:20-alpine

WORKDIR /app
COPY package.json /app

COPY package*.json ./

RUN npm install
COPY . /app

COPY . .

RUN npm run build
CMD ["npm", "start"]
EXPOSE 3001
CMD ["node", "dist/src/app.js"]

4 changes: 3 additions & 1 deletion config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ f7nAWWlOhIzawxMKZwIDAQAB
verify_link: process.env.VERIFY_LINK,
reset_link: process.env.RESET_LINK,
number_of_questions: 10,
test_duration: 35,
test_duration: 8640,
mailgun_api_key: process.env.MAILGUN_API_KEY,
email_domain: process.env.EMAIL_DOMAIN,
mailgun_host: process.env.MAILGUN_HOST,
Expand All @@ -42,4 +42,6 @@ f7nAWWlOhIzawxMKZwIDAQAB
management_cutoff: 8,
design_cutoff: 7,
video_cutoff: 7,
access_key: process.env.ACCESSKEY,
secret_key: process.env.SECRETKEY,
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
},
"dependencies": {
"@google-cloud/logging-winston": "^4.1.1",
"aws-sdk": "^2.1538.0",
"axios": "^0.25.0",
"bcrypt": "^5.0.0",
"config": "^3.3.7",
Expand Down
24 changes: 12 additions & 12 deletions src/controller/question.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,28 @@ export default async function questionHandler(
}

const easyquestions = await getQuestion(domain, "Easy");
const mediumquestions = await getQuestion(domain, "Medium");
const hardquestions = await getQuestion(domain, "Hard");
// const mediumquestions = await getQuestion(domain, "Medium");
// const hardquestions = await getQuestion(domain, "Hard");

const easyshuffled = easyquestions.sort(() => 0.5 - Math.random());
let selected = easyshuffled.slice(0, 5);
// const easyshuffled = easyquestions.sort(() => 0.5 - Math.random());
// let selected = easyshuffled.slice(0, 5);

const mediumshuffled = mediumquestions.sort(() => 0.5 - Math.random());
const mediumselected = mediumshuffled.slice(0, 3);
// const mediumshuffled = mediumquestions.sort(() => 0.5 - Math.random());
// const mediumselected = mediumshuffled.slice(0, 3);

const hardshuffled = hardquestions.sort(() => 0.5 - Math.random());
const hardselected = hardshuffled.slice(0, 2);
// const hardshuffled = hardquestions.sort(() => 0.5 - Math.random());
// const hardselected = hardshuffled.slice(0, 2);

selected = selected.concat(hardselected);
selected = selected.concat(mediumselected);
// selected = selected.concat(hardselected);
// selected = selected.concat(mediumselected);

user.questionLoaded = selected;
user.questionLoaded = easyquestions;
await user.save();
// const questionIds = user.questionLoaded.map((ques) => ques.quesId);
// logger.info(success_codes.S2, { questionIds: questionIds });
return res.status(200).send(
errorObject(200, "", {
questions: selected,
questions: easyquestions,
endTime: user.endTime,
})
);
Expand Down
8 changes: 4 additions & 4 deletions src/middleware/checkEnrolled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ const checkEnrolled = (
}

const universityEmailRegex =
/^[a-zA-Z]+\.([a-zA-Z]+\.)?[a-zA-Z]+(20(20|21|22|23))@vitstudent\.ac\.in$/;
/^[a-zA-Z]+\.([a-zA-Z]+\.)?[a-zA-Z]*(20(20|21|22|23))[a-z]*@vitstudent\.ac\.in$/;

if (!universityEmailRegex.test(email)) {
return res.status(200).send(errorObject(403, "Not an Vit Email id"));
}

if (email.match(universityEmailRegex)[1] !== "2023") {
return res.status(200).send(errorObject(403, "Not a Fresher"));
}
// if (email.match(universityEmailRegex)[2] !== "2023") {
// return res.status(200).send(errorObject(403, "Not a Fresher"));
// }

if (!isStringPresentInJsonFile(email, "enrolledlist.json")) {
return res.status(200).send(errorObject(403, "Not enrolled in CSI"));
Expand Down
10 changes: 9 additions & 1 deletion src/middleware/limitDomains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ const limitDomains = async (
return res.status(200).send(errorObject(403, "not logged in"));
}
const userInfo = await getCcsUserDomains(user._id);
if (userInfo.domainsAttempted.length >= 2) {
let attemptedDomains = 0;

userInfo.domainsAttempted.forEach((domain) => {
if (domain.submitted) {
attemptedDomains += 1;
}
});

if (attemptedDomains >= 2) {
return res
.status(200)
.send(errorObject(403, "2 domain quizes already filled"));
Expand Down
2 changes: 1 addition & 1 deletion src/models/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const userSchema = new mongoose.Schema(
},
verificationStatus: {
type: Boolean,
default: true,
default: false,
required: true,
},
passwordResetToken: {
Expand Down
8 changes: 2 additions & 6 deletions src/service/ccsUser.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,14 @@ export async function createCcsUser(
export async function getAllUsers() {
let users = await ccsUserModel
.find({
$and: [
{ $or: [{ endTime: { $lt: new Date() } }, { endTime: null }] },
{ domainsAttempted: { $exists: true, $not: { $size: 0 } } },
],
domainsAttempted: { $elemMatch: { submitted: true } },
})
.populate("userId", ["regNo", "name"])
.select(
"username domainsAttempted techRound managementRound marks designRound videoRound userId checked isChecking"
);
console.log(users);
users = users.filter((user) =>
["20", "21", "22"].includes(
["22", "23"].includes(
(user.userId as unknown as UserDocument).regNo.slice(0, 2)
)
);
Expand Down
2 changes: 1 addition & 1 deletion src/service/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function createUser(input: UserInput) {
username: ccsUser.username,
message: "User created in accounts and ccs DB",
});
// sendVerificationMail(user);
sendVerificationMail(user);
jsonResponse.success = true;
jsonResponse.message = constants.registrationSuccess;
return jsonResponse;
Expand Down
1 change: 0 additions & 1 deletion src/tools/r2Mails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const sendR2Mail = async () => {
.filter(([, value]) => value >= 8)
.map(([key]) => key),
}));
console.log(reducedUsers);
// const data = {
// from: `CSI-VIT <${senderEmail}>`,
// to: email,
Expand Down
75 changes: 52 additions & 23 deletions src/tools/sendMail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ import config from "config";
import url from "url";
import { create } from "express-handlebars";
import https from "https";
// eslint-disable-next-line import/no-extraneous-dependencies
import AWS from "aws-sdk";
import { constants } from "./constants";
import { UserDocument } from "../models/user.model";
import logger from "../utils/logger";

const SES_CONFIG = {
accessKeyId: config.get<string>("access_key"),
secretAccessKey: config.get<string>("secret_key"),
region: "ap-south-1",
};

const ses = new AWS.SES(SES_CONFIG);
const mailgun = new Mailgun(formData);
const mg = mailgun.client({
username: "api",
Expand All @@ -24,36 +33,56 @@ export const sendMail = async (
link: string
) => {
try {
const data = {
to: email,
text: link,
subject,
html: content,
auth: config.get<string>("emailer_auth"),
};
// const data = {
// from: senderEmail,
// to: email,
// text: link,
// subject,
// html: content,
// };

const postOptions = {
host: config.get<string>("emailer_host"),
port: "443",
path: config.get<string>("emailer_path"),
method: "POST",
headers: {
"Content-Type": "application/json",
"Content-Length": Buffer.byteLength(JSON.stringify(data)),
const params = {
Source: "Team CSI <[email protected]>",
Destination: {
ToAddresses: [email],
},
Message: {
Subject: {
Data: subject,
},
Body: {
Html: {
Data: content,
},
},
},
};
await ses.sendEmail(params).promise();

// const postOptions = {
// host: config.get<string>("emailer_host"),
// port: "443",
// path: config.get<string>("emailer_path"),
// method: "POST",
// headers: {
// "Content-Type": "application/json",
// "Content-Length": Buffer.byteLength(JSON.stringify(data)),
// },
// };

// Set up the request
const postReq = https.request(postOptions, (res) => {
res.setEncoding("utf8");
res.on("data", (chunk) => {
logger.info(`mail sent to ${email} Response: `, chunk);
});
});
// const postReq = https.request(postOptions, (res) => {
// res.setEncoding("utf8");
// res.on("data", (chunk) => {
// logger.info(`mail sent to ${email} Response: `, chunk);
// });
// });

// post the data
postReq.write(JSON.stringify(data));
postReq.end();
// postReq.write(JSON.stringify(data));
// postReq.end();
// await mg.messages.create(domain, data);
// console.log(data);
// await mg.messages.create(domain, data);
logger.info(`Mail sent to ${email} successfully`);
} catch (e) {
Expand Down

0 comments on commit c6bf140

Please sign in to comment.