Skip to content

Commit

Permalink
Merge pull request #119 from IEEEUCSC/main
Browse files Browse the repository at this point in the history
Added sessions registraions
  • Loading branch information
Udeesha-Prabhashana authored Feb 2, 2024
2 parents ca22b1d + 50d1834 commit 3162a84
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 9 deletions.
2 changes: 2 additions & 0 deletions backend/dist/Controllers/sessionReg.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const register = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
number: req.body.number,
university: req.body.university,
year: req.body.year,
platform: req.body.platform,
design: req.body.design,
});
yield newSession.save();
res.status(200).json({
Expand Down
123 changes: 123 additions & 0 deletions backend/dist/Controllers/team.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTeams = exports.count = exports.register = void 0;
const team_1 = __importDefault(require("../Model/team"));
const dotenv_1 = __importDefault(require("dotenv"));
dotenv_1.default.config();
const AUTH_KEY = process.env.AUTH_KEY || "";
const expectTeamCount = 65;
const teamCount = () => __awaiter(void 0, void 0, void 0, function* () {
try {
const count = yield team_1.default.countDocuments({});
console.log("Number of teams:", count);
return count;
}
catch (err) {
console.error('Error counting teams:', err);
throw err;
}
});
const register = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
// count teams and return if 50 teams are already registered
const count = yield teamCount();
if (count >= expectTeamCount) {
res.status(200).json({
success: false,
message: "Registration is currently closed because the maximum number of teams has been reached.",
});
return;
}
else {
try {
const newSession = new team_1.default({
teamName: req.body.teamName,
university: req.body.university,
other: req.body.other,
leaderName: req.body.leaderName,
leaderYear: req.body.leaderYear,
leaderWhatsapp: req.body.leaderWhatsapp,
leaderEmail: req.body.leaderEmail,
leaderNIC: req.body.leaderNIC,
member1Name: req.body.member1Name,
member1Year: req.body.member1Year,
member1Whatsapp: req.body.member1Whatsapp,
member1Email: req.body.member1Email,
member1NIC: req.body.member1NIC,
member2Name: req.body.member2Name,
member2Year: req.body.member2Year,
member2Whatsapp: req.body.member2Whatsapp,
member2Email: req.body.member2Email,
member2NIC: req.body.member2NIC,
member3Name: req.body.member3Name,
member3Year: req.body.member3Year,
member3Whatsapp: req.body.member3Whatsapp,
member3Email: req.body.member3Email,
member3NIC: req.body.member3NIC,
});
yield newSession.save();
res.status(200).json({
success: true,
message: "Registered successfully",
data: newSession,
});
}
catch (err) {
res.status(500).json({
success: false,
message: "Registration failed",
data: err,
});
console.log(err);
}
}
});
exports.register = register;
const count = (req, res) => {
team_1.default.countDocuments({}).then(count => {
console.log("Number of teams:", count);
res.status(200).json({ teamCount: expectTeamCount - count });
}).catch(err => {
console.error('Error counting teams:', err);
res.status(500).send('Error counting teams');
});
};
exports.count = count;
// get teams , autherization key is required
const getTeams = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const authKey = req.headers.authorization;
if (authKey !== AUTH_KEY) {
res.status(401).json({
success: false,
message: "Unauthorized",
});
return;
}
try {
const teams = yield team_1.default.find({});
res.status(200).json({
success: true,
message: "Teams fetched successfully",
data: teams,
});
}
catch (err) {
res.status(500).json({
success: false,
message: "Error fetching teams",
data: err,
});
}
});
exports.getTeams = getTeams;
12 changes: 10 additions & 2 deletions backend/dist/Model/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ const sessionSchema = new mongoose_1.default.Schema({
year: {
type: String,
required: true
}
},
platform: {
type: String,
required: true
},
design: {
type: String,
required: true
},
});
// interface ISession extends Document {
// email: string;
Expand All @@ -33,4 +41,4 @@ const sessionSchema = new mongoose_1.default.Schema({
// university: string;
// year: string;
// }
exports.default = mongoose_1.default.model('Session', sessionSchema);
exports.default = mongoose_1.default.model('AppDesginSession', sessionSchema);
156 changes: 156 additions & 0 deletions backend/dist/Model/team.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const mongoose_1 = __importDefault(require("mongoose"));
// const sessionSchema = new mongoose.Schema({
// email: {
// type: String,
// required: true
// },
// name: {
// type: String,
// required: true
// },
// number:{
// type: String,
// required: true
// },
// university:{
// type: String,
// required: true
// },
// year:{
// type: String,
// required: true
// },
// platform:{
// type: String,
// required: true
// },
// design:{
// type: String,
// required: true
// },
// });
// //{
// teamName: 'Megane Frami',
// university: 'University of Ruhuna',
// other: 'Culpa sapiente animi provident quod voluptas.',
// leaderName: 'Josue.Crooks',
// leaderYear: '2nd year',
// leaderWhatsapp: '369-359-1569',
// leaderEmail: '[email protected]',
// leaderNIC: 'Facere hic eius laboriosam sint cumque rerum ad cum.',
// member1Name: 'Caitlyn45',
// member1Year: '4th year',
// member1Whatsapp: '685-528-3764',
// member1Email: '[email protected]',
// member1NIC: '540',
// member2Name: 'Sally4',
// member2Year: '2nd year',
// member2Whatsapp: '007-837-0355',
// member2Email: '[email protected]',
// member2NIC: '13',
// member3Name: 'Lula.Bradtke',
// member3Year: '3rd year',
// member3Whatsapp: '971-866-6326',
// member3Email: '[email protected]',
// member3NIC: '522'
// }
const teamSchema = new mongoose_1.default.Schema({
teamName: {
type: String,
required: true
},
university: {
type: String,
required: true
},
other: {
type: String,
required: false
},
leaderName: {
type: String,
required: true
},
leaderYear: {
type: String,
required: true
},
leaderWhatsapp: {
type: String,
required: true
},
leaderEmail: {
type: String,
required: true
},
leaderNIC: {
type: String,
required: true
},
member1Name: {
type: String,
required: true
},
member1Year: {
type: String,
required: true
},
member1Whatsapp: {
type: String,
required: true
},
member1Email: {
type: String,
required: true
},
member1NIC: {
type: String,
required: true
},
member2Name: {
type: String,
required: true
},
member2Year: {
type: String,
required: true
},
member2Whatsapp: {
type: String,
required: true
},
member2Email: {
type: String,
required: true
},
member2NIC: {
type: String,
required: true
},
member3Name: {
type: String,
required: false
},
member3Year: {
type: String,
required: false
},
member3Whatsapp: {
type: String,
required: false
},
member3Email: {
type: String,
required: false
},
member3NIC: {
type: String,
required: false
},
});
exports.default = mongoose_1.default.model('Team', teamSchema);
2 changes: 1 addition & 1 deletion backend/dist/Routes/sessionReg.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const sessionReg_1 = require("../Controllers/sessionReg");
const router = express_1.default.Router();
router.post("/", sessionReg_1.register);
router.post("/register", sessionReg_1.register);
exports.default = router;
12 changes: 12 additions & 0 deletions backend/dist/Routes/team.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const team_1 = require("../Controllers/team");
const router = express_1.default.Router();
router.post("/register", team_1.register);
router.get("/count", team_1.count);
router.get("/getTeams", team_1.getTeams);
exports.default = router;
19 changes: 14 additions & 5 deletions backend/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ const express_1 = __importDefault(require("express"));
const cors_1 = __importDefault(require("cors"));
const mongoose_1 = __importDefault(require("mongoose"));
const dotenv_1 = __importDefault(require("dotenv"));
const team_1 = __importDefault(require("./Routes/team"));
const sessionReg_1 = __importDefault(require("./Routes/sessionReg"));
dotenv_1.default.config();
const URL = process.env.MONGO || "";
const URL = process.env.MONGO || "mongodb://localhost:27017/";
const ORIGIN = process.env.ORIGIN || "http://localhost:3000";
const PORT = process.env.PORT || 4000;
const AUTH_KEY = process.env.AUTH_KEY || "123456";
const app = (0, express_1.default)();
app.use(express_1.default.json());
app.use((0, cors_1.default)({
origin: "http://localhost:3000",
origin: ORIGIN,
methods: ["GET", "POST", "PUT", "DELETE"]
}));
// app.post("/api/register", (req: Request, res: Response) => {
Expand All @@ -33,7 +37,12 @@ app.use((0, cors_1.default)({
// console.log(response);
// res.send(response);
// });
app.use("/api/register", sessionReg_1.default);
// Api is running
app.get("/", (req, res) => {
res.send("MADHACK API is running");
});
app.use("/api/team", team_1.default);
app.use("/api/session", sessionReg_1.default);
const connect = () => __awaiter(void 0, void 0, void 0, function* () {
try {
yield mongoose_1.default.connect(URL);
Expand All @@ -46,7 +55,7 @@ const connect = () => __awaiter(void 0, void 0, void 0, function* () {
mongoose_1.default.connection.on("disconnected", () => {
console.log("mongoDB disconnected!");
});
app.listen(4011, () => {
app.listen(PORT, () => {
connect();
console.log("Server running on port 4011");
console.log("Server running on port " + PORT);
});
2 changes: 1 addition & 1 deletion backend/src/Routes/sessionReg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { register } from "../Controllers/sessionReg";

const router = express.Router();

router.post("/session", register);
router.post("/register", register);

export default router;

0 comments on commit 3162a84

Please sign in to comment.