Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

Commit

Permalink
updated server url
Browse files Browse the repository at this point in the history
  • Loading branch information
BuddyLongLegs committed Aug 24, 2023
1 parent 8aef537 commit ab9cbdb
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 299 deletions.
10 changes: 5 additions & 5 deletions API_Endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ The following properties of every endpoint will be descibed in this file:
"id": "Project Id"
"name": "Project Name",
"form_count": 5,
"allowed_origins": ["http://localhost", "https://savemyform.tk"],
"allowed_origins": ["http://localhost", "https://savemyform.in.net"],
"date_created": "date-of-creation"
}
]
Expand Down Expand Up @@ -244,7 +244,7 @@ The following properties of every endpoint will be descibed in this file:
"hasRecaptcha": true,
"recaptchaKey": "User's project Recaptcha Key",
"recaptchaSecret": "User's project Recaptcha Secret",
"allowedOrigins": ["http://localhost", "https://savemyform.tk"],
"allowedOrigins": ["http://localhost", "https://savemyform.in.net"],
"collaborators": ["[email protected]", "[email protected]"],
"recaptcha_token": "Google Recaptcha Token recieved from Google"
}
Expand Down Expand Up @@ -283,7 +283,7 @@ The following properties of every endpoint will be descibed in this file:
"hasRecaptcha": true,
"recaptchaKey": "User's project Recaptcha Key",
"recaptchaSecret": "User's project Recaptcha Secret",
"allowedOrigins": ["http://localhost", "https://savemyform.tk"],
"allowedOrigins": ["http://localhost", "https://savemyform.in.net"],
"form_count": 2,
"forms":[
{
Expand All @@ -309,7 +309,7 @@ The following properties of every endpoint will be descibed in this file:
"hasRecaptcha": true,
"recaptchaKey": "User's project Recaptcha Key",
"recaptchaSecret": "User's project Recaptcha Secret",
"allowedOrigins": ["http://localhost", "https://savemyform.tk"],
"allowedOrigins": ["http://localhost", "https://savemyform.in.net"],
"collaborators": ["[email protected]", "[email protected]"],
"recaptcha_token": "Google Recaptcha Token recieved from Google",
"password": "user's password"
Expand All @@ -335,7 +335,7 @@ The following properties of every endpoint will be descibed in this file:
"hasRecaptcha": true,
"recaptchaKey": "User's project Recaptcha Key",
"recaptchaSecret": "User's project Recaptcha Secret",
"allowedOrigins": ["http://localhost", "https://savemyform.tk"],
"allowedOrigins": ["http://localhost", "https://savemyform.in.net"],
}
```

Expand Down
2 changes: 1 addition & 1 deletion controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const client = new OAuth2Client(
process.env.GOOGLE_OAUTH_CLIENT_ID,
process.env.GOOGLE_OAUTH_CLIENT_SECRET,
process.env.ENV === 'prod'
? 'https://savemyform.tk/signin/oauth'
? 'https://savemyform.in.net/signin/oauth'
: 'http://localhost:3000/signin/oauth',
);

Expand Down
37 changes: 10 additions & 27 deletions controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,30 +124,12 @@ export async function updateProject(req, res) {
updatedProject.allowedOrigins = req.body.allowedOrigins;
}

if (req.body.collaborators) {
if (req.body.collaborators.length > 5) {
return response_400(
res,
'Number of collaborators cannot be greater than 5',
);
}
inviteCollaborators(
req.body.collaborators,
projectId,
req.body.name,
req.user.name,
req.user.email,
);
}

// updating the project details in DB
const finalProject = await Project.findOneAndUpdate(
{ projectId: projectId },
updatedProject,
{ returnDocument: 'after', select: '-_id -forms' },
)
.populate({ path: 'owner', select: '-_id name email' })
.populate({ path: 'collaborators', select: '-_id name email' });
).populate({ path: 'owner', select: '-_id name email' });

finalProject.is_owner = req.user.id === finalProject.owner;

Expand All @@ -160,15 +142,17 @@ export async function updateProject(req, res) {
export async function projectDashboard(req, res) {
let project = await Project.findOne({ projectId: req.params.id });
if (!project) return response_400(res, 'No project with this id');
let allow = project.collaborators.includes(req.user._id);
let allow = Collaborators.exists({
email: req.user.email,
projectId: project._id,
});
if (!allow && String(project.owner) !== String(req.user._id))
return response_400(res, 'You cannot access this project');

try {
project = await Project.findOne({ projectId: req.params.id })
.populate('forms', 'formId name submission createdAt updatedAt -_id')
.populate('owner', 'name email')
.populate('collaborators', 'name email -_id')
.select('-_id -createdAt -updatedAt -__v');
project = project.toJSON();
project.is_owner = String(project.owner._id) === String(req.user._id);
Expand Down Expand Up @@ -267,14 +251,13 @@ export async function updateCollaborator(req, res) {

export async function updateCollaboratorStatus(req, res) {
try {
if(req.body.userAccepted){
let collaborator=await Collaborators.findById(req.body.collaboratorId);
collaborator.status='Accepted'
if (req.body.userAccepted) {
let collaborator = await Collaborators.findById(req.body.collaboratorId);
collaborator.status = 'Accepted';
collaborator.save();
}
else{
} else {
await Collaborators.findByIdAndDelete(req.body.collaboratorId);
}
}
} catch (error) {
console.log(error);
return response_500(res, 'Server error', error);
Expand Down
13 changes: 13 additions & 0 deletions controllers/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { verifycaptcha } from '../utils/recaptcha.js';
import validator from 'validator';
import jwt from 'jsonwebtoken';
import User from '../models/user.model.js';
import InvitedCollaborator from '../models/invitedCollaborators.model.js';

export function getVerificationLink(req, res) {
if (req.user.verified)
Expand Down Expand Up @@ -111,7 +112,19 @@ export async function dashboard(req, res) {
options: { sort: { createdAt: -1 } },
select: 'projectId name forms allowedOrigins createdAt',
});
let collaboratedProjects = await InvitedCollaborator.find({
status: 'Accepted',
email: req.user.email,
})
.populate({
path: 'projectId',
select: 'projectId name forms allowedOrigins createdAt',
})
.toJSON();
user = await user.toJSON();
collaboratedProjects.forEach((collabProjectObj) => {
user.projects.push(collabProjectObj.projectId);
});
user.project_count = user.projects.length;
user.projects.map((project) => {
project.date_created = project.createdAt;
Expand Down
Loading

0 comments on commit ab9cbdb

Please sign in to comment.