-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from IEEEUCSC/main
Added sessions registraions
- Loading branch information
Showing
8 changed files
with
319 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters