diff --git a/package.json b/package.json index 79264f5..7325445 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/models/countries.ts b/src/models/countries.ts new file mode 100644 index 0000000..7514532 --- /dev/null +++ b/src/models/countries.ts @@ -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 +} + +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 }, + videoURL: { type: String, required: true }, + sights: { type: Array, required: true }, +}) + +export const Countries = mongoose.model('Countries', CountrySchema); diff --git a/src/routes/countries.ts b/src/routes/countries.ts new file mode 100644 index 0000000..e5e4a0d --- /dev/null +++ b/src/routes/countries.ts @@ -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) + } +) diff --git a/src/routes/index.ts b/src/routes/index.ts index 8bc00ae..2ef441b 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -1,5 +1,6 @@ import express from 'express' import { authRouter } from './auth' +import { countriesRouter } from './countries' export interface IRoute { endpoint: string @@ -14,4 +15,5 @@ root.get('/', async (req: express.Request, res: express.Response, next: express. export const routes: Array = [ { endpoint: '/', router: root }, { endpoint: '/auth', router: authRouter }, + { endpoint: '/countries', router: countriesRouter }, ]