瀏覽代碼

updated routes

master
kj1352 4 年之前
父節點
當前提交
6b9835614c
共有 4 個檔案被更改,包括 14 行新增18 行删除
  1. +5
    -5
      src/index.ts
  2. +3
    -4
      src/user-profile/category-routes.ts
  3. +3
    -6
      src/user-profile/shelf-routes.ts
  4. +3
    -3
      src/user-profile/word-routes.ts

+ 5
- 5
src/index.ts 查看文件

@@ -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'));


+ 3
- 4
src/user-profile/category-routes.ts 查看文件

@@ -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());
}


+ 3
- 6
src/user-profile/shelf-routes.ts 查看文件

@@ -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());
}


+ 3
- 3
src/user-profile/word-routes.ts 查看文件

@@ -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) {


Loading…
取消
儲存