Skip to content

Commit

Permalink
added interview routes
Browse files Browse the repository at this point in the history
  • Loading branch information
shweta3047 committed Jan 20, 2021
1 parent 2378feb commit e09af38
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
29 changes: 26 additions & 3 deletions rce-server/server/api/controllers/Interview/controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
import Server from "../../../common/server";
import InterviewService from "../../services/interview.service";
const BASE_URI = process.env.BASE_URI;

export class Controller {
async connect(req, res) {
const uid = req.params.uid;
console.log(uid);
try {
if (!req.user) {
throw {
message: "User must be logged in!!",
};
} else {
const uid = req.params.uid;
const link = `${BASE_URI}/interview/${uid}`;
console.log(uid);
output = await InterviewService.execute(link, user);
if (output) {
res.json({
status: 200,
message: "Connected to interview",
output,
});
}
}
} catch (error) {
res.send({
status: error.status || "500",
message: error.message || "Something Went Wrong",
});
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion rce-server/server/api/controllers/Interview/router.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as express from "express";
import controller from "./controller";
import isLoggedIn from "../../middlewares/isLogged.handler";

export default express.Router().post("/:uid", controller.connect);
export default express.Router().get("/:uid", isLoggedIn, controller.connect);
2 changes: 1 addition & 1 deletion rce-server/server/api/controllers/Links/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import LinkService from "../../services/link.service";
export class Controller {
async generateLink(req, res) {
try {
console.log(req.user);
// console.log(req.user);
if (!req.user) {
throw {
message: "User must be logged in!!",
Expand Down
4 changes: 2 additions & 2 deletions rce-server/server/api/controllers/Links/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export default express
.Router()
.post("/generate", isLoggedIn, controller.generateLink)
.post("/delete", isLoggedIn, controller.deleteLink)
.post("/addEmail", isLoggedIn, controller.addEmail)
.post("/removeEmail", isLoggedIn, controller.removeEmail);
.put("/addEmail", isLoggedIn, controller.addEmail)
.put("/removeEmail", isLoggedIn, controller.removeEmail);
27 changes: 27 additions & 0 deletions rce-server/server/api/services/interview.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import mongoose from "mongoose";
const Link = require("../../models/link");

class InterviewService {
async execute(link, user) {
try {
const isLink = await Link.findOne({ link })
.populate("interviewer")
.populate("interviewee");
if (isLink) {
if (user._id.toString() == isLink.interviewer.toString()) {
return isLink;
} else {
}
} else {
throw {
status: 404,
message: "Invalid link",
};
}
} catch (error) {
throw error;
}
}
}

export default new InterviewService();
2 changes: 1 addition & 1 deletion rce-server/server/api/services/link.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class LinkService {
async generate(user) {
try {
const uid = crypto.randomBytes(16).toString("hex");
const link = BASE_URI + uid;
const link = `${BASE_URI}/interview/${uid}`;

const generatedLink = await Link.create({
link,
Expand Down

0 comments on commit e09af38

Please sign in to comment.