| @@ -18,11 +18,11 @@ app.use(cors()); | |||||
| app.use(express.json()); | app.use(express.json()); | ||||
| app.use(passport.initialize()); | app.use(passport.initialize()); | ||||
| app.set('port', process.env.PORT || 8001); | app.set('port', process.env.PORT || 8001); | ||||
| app.use('/', authRoutes); | |||||
| app.use('/', userProfileRoutes); | |||||
| app.use('/', categoryRoutes); | |||||
| app.use('/', shelfRoutes); | |||||
| app.use('/', wordRoutes); | |||||
| app.use('/auth/', authRoutes); | |||||
| app.use('/user/', userProfileRoutes); | |||||
| app.use('/category/', categoryRoutes); | |||||
| app.use('/shelf/', shelfRoutes); | |||||
| app.use('/library/', wordRoutes); | |||||
| app.get('/', (request, response) => { | app.get('/', (request, response) => { | ||||
| response.send('Server running @ port' + app.get('port')); | response.send('Server running @ port' + app.get('port')); | ||||
| @@ -11,7 +11,7 @@ export const categoryRoutes = express.Router(); | |||||
| export const jwtAuthentication = passport.authenticate('jwt', { session: false }); | export const jwtAuthentication = passport.authenticate('jwt', { session: false }); | ||||
| // Get Category Details | // Get Category Details | ||||
| categoryRoutes.get('/category/', jwtAuthentication, async (request, response) => { | |||||
| categoryRoutes.get('/details/', jwtAuthentication, async (request, response) => { | |||||
| const categoryCollection = getDatabaseClient().db(DB_NAME).collection<MongoCategory>('categories'); | const categoryCollection = getDatabaseClient().db(DB_NAME).collection<MongoCategory>('categories'); | ||||
| const currentCategory = await categoryCollection.findOne({ | const currentCategory = await categoryCollection.findOne({ | ||||
| @@ -31,7 +31,7 @@ categoryRoutes.get('/category/', jwtAuthentication, async (request, response) => | |||||
| // Add category | // Add category | ||||
| categoryRoutes.post('/category/', jwtAuthentication, async (request, response) => { | |||||
| categoryRoutes.post('/add/', jwtAuthentication, async (request, response) => { | |||||
| const user: MongoUser = (request.user as any); | const user: MongoUser = (request.user as any); | ||||
| const categoryCollection = getDatabaseClient().db(DB_NAME).collection<MongoCategory>('categories'); | const categoryCollection = getDatabaseClient().db(DB_NAME).collection<MongoCategory>('categories'); | ||||
| @@ -75,7 +75,7 @@ categoryRoutes.post('/category/', jwtAuthentication, async (request, response) = | |||||
| // Update category | // Update category | ||||
| categoryRoutes.put('/category/', jwtAuthentication, async (request, response) => { | |||||
| categoryRoutes.put('/update/', jwtAuthentication, async (request, response) => { | |||||
| const categoryCollection = getDatabaseClient().db(DB_NAME).collection('categories'); | const categoryCollection = getDatabaseClient().db(DB_NAME).collection('categories'); | ||||
| const currentCategory = await categoryCollection.findOne({ | const currentCategory = await categoryCollection.findOne({ | ||||
| @@ -110,7 +110,6 @@ categoryRoutes.put('/category/', jwtAuthentication, async (request, response) => | |||||
| response.sendStatus(200); | response.sendStatus(200); | ||||
| } catch (e) { | } catch (e) { | ||||
| console.log(e); | |||||
| response.status(400); | response.status(400); | ||||
| response.send(e.toString()); | response.send(e.toString()); | ||||
| } | } | ||||
| @@ -12,7 +12,7 @@ export const jwtAuthentication = passport.authenticate('jwt', { session: false } | |||||
| // GET shelf details | // GET shelf details | ||||
| shelfRoutes.get('/shelf/', jwtAuthentication, async (request, response) => { | |||||
| shelfRoutes.get('/details/', jwtAuthentication, async (request, response) => { | |||||
| const shelfCollection = getDatabaseClient().db(DB_NAME).collection<MongoShelf>('shelves'); | const shelfCollection = getDatabaseClient().db(DB_NAME).collection<MongoShelf>('shelves'); | ||||
| const currentShelf = await shelfCollection.findOne({ | const currentShelf = await shelfCollection.findOne({ | ||||
| @@ -32,7 +32,7 @@ shelfRoutes.get('/shelf/', jwtAuthentication, async (request, response) => { | |||||
| // Add shelf | // Add shelf | ||||
| shelfRoutes.post('/shelf/', jwtAuthentication, async (request, response) => { | |||||
| shelfRoutes.post('/add/', jwtAuthentication, async (request, response) => { | |||||
| const categoryCollection = getDatabaseClient().db(DB_NAME).collection<MongoCategory>('categories'); | const categoryCollection = getDatabaseClient().db(DB_NAME).collection<MongoCategory>('categories'); | ||||
| const shelfCollection = getDatabaseClient().db(DB_NAME).collection<MongoShelf>('shelves'); | const shelfCollection = getDatabaseClient().db(DB_NAME).collection<MongoShelf>('shelves'); | ||||
| @@ -94,10 +94,8 @@ shelfRoutes.post('/shelf/', jwtAuthentication, async (request, response) => { | |||||
| return; | return; | ||||
| }); | }); | ||||
| // Update shelf | // Update shelf | ||||
| shelfRoutes.put('/shelf/', jwtAuthentication, async (request, response) => { | |||||
| shelfRoutes.put('/update/', jwtAuthentication, async (request, response) => { | |||||
| const shelfCollection = getDatabaseClient().db(DB_NAME).collection<MongoShelf>('shelves'); | const shelfCollection = getDatabaseClient().db(DB_NAME).collection<MongoShelf>('shelves'); | ||||
| const currentShelf = await shelfCollection.findOne({ | const currentShelf = await shelfCollection.findOne({ | ||||
| @@ -131,7 +129,6 @@ shelfRoutes.put('/shelf/', jwtAuthentication, async (request, response) => { | |||||
| response.sendStatus(200); | response.sendStatus(200); | ||||
| } catch (e) { | } catch (e) { | ||||
| console.log(e); | |||||
| response.status(400); | response.status(400); | ||||
| response.send(e.toString()); | response.send(e.toString()); | ||||
| } | } | ||||
| @@ -9,7 +9,7 @@ export const jwtAuthentication = passport.authenticate('jwt', { session: false } | |||||
| // Get All Words | // Get All Words | ||||
| wordRoutes.get('/all-words/', jwtAuthentication, async (request, response) => { | |||||
| wordRoutes.get('/all/', jwtAuthentication, async (request, response) => { | |||||
| const wordCollection = getDatabaseClient().db(DB_NAME).collection<Word>('words'); | const wordCollection = getDatabaseClient().db(DB_NAME).collection<Word>('words'); | ||||
| const allWords = await wordCollection.find().toArray(); | const allWords = await wordCollection.find().toArray(); | ||||
| @@ -20,7 +20,7 @@ wordRoutes.get('/all-words/', jwtAuthentication, async (request, response) => { | |||||
| return; | return; | ||||
| }); | }); | ||||
| wordRoutes.get('/word/', jwtAuthentication, async (request, response) => { | |||||
| wordRoutes.get('/search/', jwtAuthentication, async (request, response) => { | |||||
| const wordCollection = getDatabaseClient().db(DB_NAME).collection<Word>('words'); | const wordCollection = getDatabaseClient().db(DB_NAME).collection<Word>('words'); | ||||
| if (!request.body.name) { | if (!request.body.name) { | ||||
| @@ -39,7 +39,7 @@ wordRoutes.get('/word/', jwtAuthentication, async (request, response) => { | |||||
| return; | return; | ||||
| }); | }); | ||||
| wordRoutes.post('/word/', jwtAuthentication, async (request, response) => { | |||||
| wordRoutes.post('/add/', jwtAuthentication, async (request, response) => { | |||||
| const wordCollection = getDatabaseClient().db(DB_NAME).collection<Word>('words'); | const wordCollection = getDatabaseClient().db(DB_NAME).collection<Word>('words'); | ||||
| if (!request.body.name || request.body.grammaticalDetails) { | if (!request.body.name || request.body.grammaticalDetails) { | ||||