forked from PalisadoesFoundation/talawa-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
960d2c8
commit 1bae7d5
Showing
15 changed files
with
2,974 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
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,4 @@ | ||
{ | ||
"editor.fontFamily": "Consolas,'OperatorMono-Book', monospace", | ||
"editor.fontLigatures": | ||
} |
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,2 @@ | ||
"# tenten-api-rework" | ||
database credentials are in nodemon.json file |
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,39 @@ | ||
const { ApolloServer, gql } = require("apollo-server"); | ||
const mongoose = require("mongoose"); | ||
const Query = require("./resolvers/Query"); | ||
const Mutation = require("./resolvers/Mutation"); | ||
const typeDefs = require("./schema.graphql"); | ||
const isAuth = require("./middleware/is-auth"); | ||
const User = require("./resolvers/User") | ||
const express = require("express"); | ||
const app = express(); | ||
|
||
const resolvers = { | ||
Query, | ||
Mutation, | ||
User | ||
}; | ||
|
||
const server = new ApolloServer({ | ||
typeDefs, | ||
resolvers, | ||
context: ({ req }) => { | ||
return isAuth(req) | ||
}, | ||
}); | ||
|
||
|
||
mongoose | ||
.connect( | ||
`mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@talawa-dev-nk4oo.mongodb.net/${process.env.MONGO_DB}?retryWrites=true&w=majority`, | ||
{ | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
} | ||
) | ||
.then(() => { | ||
server.listen().then(({ url }) => { | ||
console.log(`🚀 Server ready at ${url}`); | ||
}); | ||
}) | ||
.catch((e) => console.log(e)); |
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,59 @@ | ||
const jwt = require("jsonwebtoken"); | ||
|
||
const isAuth = (req) => { | ||
//This checks to see if there is an authorization field within the incoming request | ||
const authHeader = req.headers.authorization | ||
|
||
//if there is no token | ||
if (!authHeader) { | ||
const isAuth = false; | ||
return { | ||
isAuth | ||
}; | ||
} | ||
|
||
//format of request sent will be Bearer tokenvalue | ||
//this splits it into two values bearer and the token | ||
const token = authHeader.split(" ")[1]; | ||
|
||
//if the token is null or an empty string | ||
if (!token || token === "") { | ||
const isAuth = false; | ||
return { | ||
isAuth | ||
}; | ||
} | ||
|
||
//uses key created in the auth resolver | ||
//to be changed in production | ||
//only tokens created with this key will be valid tokens | ||
let decodedToken; | ||
try { | ||
decodedToken = jwt.verify(token, "somesupersecretkey"); | ||
} catch (e) { | ||
const isAuth = false; | ||
return { | ||
isAuth | ||
}; | ||
} | ||
|
||
//if the decoded token is not set | ||
if (!decodedToken) { | ||
const isAuth = false; | ||
return { | ||
isAuth | ||
}; | ||
} | ||
|
||
//shows the user is an authenticated user | ||
const isAuth = true; | ||
//pulls data off the token | ||
const userId = decodedToken.userId; | ||
|
||
return { | ||
isAuth, | ||
userId | ||
} | ||
} | ||
|
||
module.exports = isAuth |
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,34 @@ | ||
const mongoose = require("mongoose"); | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const organizationSchema = new Schema({ | ||
name: { | ||
type:String, | ||
required:true | ||
}, | ||
description: { | ||
type:String, | ||
required:true | ||
}, | ||
creator: { | ||
type: Schema.Types.ObjectId, | ||
ref: "User", | ||
required:true | ||
}, | ||
members: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: "User" | ||
} | ||
], | ||
admins: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: "User", | ||
required:true | ||
} | ||
] | ||
}) | ||
|
||
module.exports = mongoose.model("Organization", organizationSchema); |
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,45 @@ | ||
const mongoose = require("mongoose"); | ||
const { isEmail } = require('validator'); | ||
const Schema = mongoose.Schema; | ||
|
||
|
||
const userSchema = new Schema({ | ||
firstName: { | ||
type: String, | ||
required: true | ||
}, | ||
lastName: { | ||
type: String, | ||
required: true | ||
}, | ||
email: { | ||
type: String, | ||
validate: [ isEmail, 'invalid email' ], | ||
required: true | ||
}, | ||
password: { | ||
type: String, | ||
required: true | ||
}, | ||
createdOrganizations: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: "Organization" | ||
} | ||
], | ||
joinedOrganizations: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: "Organization" | ||
} | ||
], | ||
adminFor: [ | ||
{ | ||
type: Schema.Types.ObjectId, | ||
ref: "Organization" | ||
} | ||
] | ||
}) | ||
|
||
module.exports = mongoose.model("User", userSchema); | ||
|
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,7 @@ | ||
{ | ||
"env" : { | ||
"MONGO_USER":"devtest876", | ||
"MONGO_PASSWORD":"DGbtoevKIx1Wajvx", | ||
"MONGO_DB":"talawa-dev" | ||
} | ||
} |
Oops, something went wrong.