-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update api structure and use database for locations page (#143)
* Move api structure to router and update locations schema * Update auth uri to match api * Use database for locations name and type * Remove location tests * Update PhotoHeader test * Format
- Loading branch information
1 parent
7feab41
commit 07b9905
Showing
17 changed files
with
211 additions
and
94 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
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
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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,23 +1,44 @@ | ||
import mongoose, { Schema, Document } from 'mongoose'; | ||
|
||
export interface ILocationsModel extends Document { | ||
export interface ILocation extends Document { | ||
name: string; | ||
id: string; | ||
type?: string; | ||
} | ||
|
||
const locationsSchema = new Schema({ | ||
id: { | ||
type: String, | ||
required: true, | ||
}, | ||
name: { | ||
type: String, | ||
required: true, | ||
}, | ||
id: { | ||
type: { | ||
type: String, | ||
required: true, | ||
}, | ||
type: String, | ||
description: { | ||
type: String, | ||
required: true, | ||
}, | ||
tile: { | ||
x: { | ||
type: Number, | ||
required: true, | ||
}, | ||
y: { | ||
type: Number, | ||
required: true, | ||
}, | ||
z: { | ||
type: Number, | ||
required: true, | ||
}, | ||
}, | ||
}); | ||
|
||
const Location = mongoose.model<ILocationsModel>('Location', locationsSchema); | ||
const Location = mongoose.model<ILocation>('Location', locationsSchema); | ||
|
||
export default Location; |
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
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 |
---|---|---|
@@ -1,36 +1,26 @@ | ||
import passport from 'passport'; | ||
import express from 'express'; | ||
|
||
const mockApp = express(); | ||
const router = express.Router(); | ||
|
||
function auth(app: typeof mockApp): void { | ||
app.get( | ||
'/auth/google', | ||
passport.authenticate('google', { | ||
scope: ['profile', 'email'], | ||
}) | ||
); | ||
router.get( | ||
'/v1/auth/google', | ||
passport.authenticate('google', { | ||
scope: ['profile', 'email'], | ||
}) | ||
); | ||
|
||
app.get( | ||
'/auth/google/callback', | ||
passport.authenticate('google', { failureRedirect: '/auth/google' }), | ||
(req, res) => { | ||
res.redirect('/'); | ||
} | ||
); | ||
|
||
app.get('/api/v1/current-user', (req, res) => { | ||
if (req.user) { | ||
res.status(200).send(req.user); | ||
} else { | ||
res.status(404).send(null); | ||
} | ||
}); | ||
|
||
app.post('/api/v1/logout', (req, res) => { | ||
req.logout(); | ||
router.get( | ||
'/v1/auth/google/callback', | ||
passport.authenticate('google', { failureRedirect: 'api/v1/auth/google' }), | ||
(req, res) => { | ||
res.redirect('/'); | ||
}); | ||
} | ||
} | ||
); | ||
|
||
router.post('/v1/auth/logout', (req, res) => { | ||
req.logout(); | ||
res.redirect('/'); | ||
}); | ||
|
||
export default auth; | ||
export default router; |
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,13 @@ | ||
import express from 'express'; | ||
import auth from './auth'; | ||
import users from './users'; | ||
import locations from './locations'; | ||
import '../config/passport'; | ||
|
||
const router = express.Router(); | ||
|
||
router.use('/', auth); | ||
router.use('/', users); | ||
router.use('/', locations); | ||
|
||
export default router; |
Oops, something went wrong.