Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Countries API #2

Merged
merged 6 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"lint": "tslint --fix -c tslint.json -t stylish -p ./tsconfig.json",
"dev:clean": "rimraf build",
"dev:build": "tsc --incremental -p tsconfig.json",
"dev:start": "MONGO_URL=mongodb://localuser:qwerty123@127.0.0.1/local-travel-app-db node --inspect -r source-map-support/register -r dotenv/config build/index.js"
"dev:start": "cross-env MONGO_URL=mongodb+srv://devuser:qwerty123@cluster0.n3gup.mongodb.net/travel-app-db node --inspect -r source-map-support/register -r dotenv/config build/index.js"
},
"dependencies": {
"body-parser": "^1.19.0",
Expand Down
49 changes: 49 additions & 0 deletions src/models/countries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import mongoose, { Schema, Document } from 'mongoose'

interface ISight extends Document {
titleEN: string
titleRU: string
titleDE: string
infoEN: string
infoRU: string
infoDE: string
pictureURL: string
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не хватает пустой строки

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Есть подозрение, что currency - это сложный тип с идентификатором валют и наименованиями на разных языках, может быть, символом. Предлагаю это обсудить

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Предлагаю делать тут трехбуквенное обозначение - USD, RUB...

pictureURL: string
videoURL: string
sights: ISight[]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Запятых в конце строки отсыпь, пожалуйста )

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sights: Array

}

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 },
videoURL: { type: String, required: true },
sights: { type: Array, required: true },
})

export const Countries = mongoose.model<ICountry>('Countries', CountrySchema);
12 changes: 12 additions & 0 deletions src/routes/countries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import express from 'express'
import { Countries } from '../models/countries'

export const countriesRouter: express.Router = express.Router()

countriesRouter.get(
'/',
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
const countries = await Countries.find({}, { _id: 0 })
res.json(countries)
}
)
2 changes: 2 additions & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express from 'express'
import { authRouter } from './auth'
import { countriesRouter } from './countries'

export interface IRoute {
endpoint: string
Expand All @@ -14,4 +15,5 @@ root.get('/', async (req: express.Request, res: express.Response, next: express.
export const routes: Array<IRoute> = [
{ endpoint: '/', router: root },
{ endpoint: '/auth', router: authRouter },
{ endpoint: '/countries', router: countriesRouter },
]