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