-
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
aa15302
commit 524bbc7
Showing
5 changed files
with
107 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,40 @@ | ||
import mongoose, { Schema, Document } from 'mongoose' | ||
import { ISight } from './sights'; | ||
|
||
export interface ICountry extends Document { | ||
id: string | ||
nameEN: string | ||
nameRU: string | ||
nameDE: string | ||
capitalEN: string | ||
capitalRU: string | ||
capitalDE: string | ||
capitalLatLng: [Number, Number] | ||
infoEN: string | ||
infoRU: string | ||
infoDE: string | ||
currency: string | ||
pictureURL: string | ||
videoURL: string | ||
sights: ISight[] | ||
} | ||
|
||
export const CountrySchema: Schema = new Schema({ | ||
id: { type: String, required: true, unique: true }, | ||
nameEN: { type: String, required: true, unique: true }, | ||
nameRU: { type: String, required: true, unique: true }, | ||
nameDE: { type: String, required: true, unique: true }, | ||
capitalEN: { type: String, required: true, unique: true }, | ||
capitalRU: { type: String, required: true, unique: true }, | ||
capitalDE: { type: String, required: true, unique: true }, | ||
capitalLatLng: { type: Array, required: true, unique: true }, | ||
infoEN: { type: String, required: true }, | ||
infoRU: { type: String, required: true }, | ||
infoDE: { type: String, required: true }, | ||
currency: { type: String, required: true }, | ||
pictureURL: { type: String, required: true, unique: true }, | ||
videoURL: { type: String, required: true, unique: true }, | ||
sights: { type: Array, required: true, unique: true }, | ||
}) | ||
|
||
export const Countries = mongoose.model<ICountry>('Countries', CountrySchema); |
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,23 @@ | ||
import mongoose, { Schema, Document } from 'mongoose' | ||
|
||
export interface ISight extends Document { | ||
countryID: string | ||
titleEN: string | ||
titleRU: string | ||
titleDE: string | ||
infoEN: string | ||
infoRU: string | ||
infoDE: string | ||
} | ||
|
||
export const SightSchema: Schema = new Schema({ | ||
countryID: { type: String, required: true }, | ||
titleEN: { type: String, required: true, unique: true }, | ||
titleRU: { type: String, required: true, unique: true }, | ||
titleDE: { type: String, required: true, unique: true }, | ||
infoEN: { type: String, required: true }, | ||
infoRU: { type: String, required: true }, | ||
infoDE: { type: String, required: true }, | ||
}) | ||
|
||
export const Sights = mongoose.model<ISight>('Sights', SightSchema); |
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,19 @@ | ||
import express from 'express' | ||
import { Countries } from '../models/countries' | ||
|
||
export const countriesRouter: express.Router = express.Router() | ||
|
||
countriesRouter.options( | ||
'/', | ||
async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
res.send(200) | ||
} | ||
) | ||
|
||
countriesRouter.get( | ||
'/', | ||
async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
const countries = await Countries.find({}) | ||
res.json(countries) | ||
} | ||
) |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import express from 'express' | ||
import { Sights } from '../models/sights' | ||
|
||
export const sightsRouter: express.Router = express.Router() | ||
|
||
sightsRouter.options( | ||
'/', | ||
async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
res.send(200) | ||
} | ||
) | ||
|
||
sightsRouter.get( | ||
'/', | ||
async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
const { _id } = req.query; | ||
const filter = _id ? { _id } : {} | ||
const sights = await Sights.find(filter) | ||
res.json(sights) | ||
} | ||
) |