diff --git a/builds/readme.md b/builds/readme.md new file mode 100644 index 0000000..b16c31f --- /dev/null +++ b/builds/readme.md @@ -0,0 +1,12 @@ +My API Call would be to + +REACT_APP_API_BASE_URL + +so we can use + +.env.production.local for our production build +and +.env.development.local for our development + +in these files we could savly store our different FQDNs + diff --git a/cars/index.js b/cars/index.js new file mode 100644 index 0000000..41ff887 --- /dev/null +++ b/cars/index.js @@ -0,0 +1,69 @@ +const express = require('express') +const app = express() +const mongoose = require('mongoose') +const Car = require('./models/cars') + +const dbURI = `mongodb+srv://cars:cars!"ยง$@cluster0.58qos.mongodb.net/myFirstDatabase?retryWrites=true&w=majority` + +mongoose.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true }) + .then(() => app.listen(3000, () => console.log("running"))) + .catch(err => console.log(err)) + + +app.get("/add", (req, res) => { + const car = new Car({ + car_id: 2, + available: { + from: 50, + to: 200 + }, + reserved: [ + { + from: 55, + to: 70 + }, + { + from: 120, + to: 130 + } + ] + }) + car.save() + .then(result => res.json(result)) + .catch(err => res.json(err)) +}) + +// Possible Query +// { +// $and: [ +// { +// reserved: { +// $not: { +// $elemMatch: { +// from: { $lte: 2 }, +// to: { $gte: 10 } +// } +// } +// } + +// }, { +// available: { +// from: { $lte: 2 }, +// to: { $gte: 10 } +// } +// } +// ] +// } + + +// { +// reserved: { +// $not: { +// $elemMatch: { +// from: { $lte: 2 }, +// to: { $gte: 10 } +// } +// } +// } + +// } \ No newline at end of file diff --git a/cars/models/cars.js b/cars/models/cars.js new file mode 100644 index 0000000..78e2345 --- /dev/null +++ b/cars/models/cars.js @@ -0,0 +1,26 @@ +const mongoose = require('mongoose') +const Schema = mongoose.Schema + +const carSchema = new Schema({ + car_id: { + type: Number, + required: true + }, + available: { + from: { + type: Number, + required: true + }, + to: { + type: Number, + required: true + } + }, + reserved: { + type: Array, + required: false + } +}, { timestamps: true }) + +const Car = mongoose.model('car', carSchema) +module.exports = Car \ No newline at end of file diff --git a/cars/readme.md b/cars/readme.md new file mode 100644 index 0000000..eb5550f --- /dev/null +++ b/cars/readme.md @@ -0,0 +1,25 @@ +My car model should have + +available: { + from: time_start, + to: time_end + }, +reserved: [ + { + from: time_start, + to: time_end + }, + ... +] + +My query should look if there is any overlap between the reserved time +{ + reserved: { + $not: { + $elemMatch: { + from: { $lte: start_time }, + to: { $gte: end_time } + } + } + } +} \ No newline at end of file diff --git a/deduplicate/main.js b/deduplicate/main.js new file mode 100644 index 0000000..b4f79ea --- /dev/null +++ b/deduplicate/main.js @@ -0,0 +1,21 @@ +const wordList = ['not', 'a', 'pheasant', 'plucker', 'but', 'a', 'pheasant', "plucker's", 'son'] +// [ 'not', 'a', 'pheasant', 'plucker', 'but', 'plucker\'s', 'son' ] + +// let temp = JSON.stringify(wordList).replace("'", "\\'") +// let temp2 = JSON.parse(temp) +// console.log(temp2) + +// const filterArray = (array) => [...new Set(array)].map(ele => JSON.stringify(ele)) +const filterArray = (array) => [...new Set(array)] +// const filterArray = (array) => [...new Set(array)].map(ele => ele.replace(/'/g, '"').replace(/"/g, String.fromCharCode(92, 39))) +// with help of spread Operator and new Set we will have an array with unique values + +const filterArray2 = (array) => array.filter((element, index, array) => (array.indexOf(element) === index)) +// const filterArray2 = (array) => array.filter((element, index, array) => (array.indexOf(element) === index)).map(ele => ele.replace("'", String.fromCharCode(92))) +// we look, where the first apperance of this element is. If it is the index it is the first time it apperce. +// If the number is bigger we dont return the element because it's already there + +console.log(filterArray(wordList)) + +// Prefered Method: (if ES6 is available) new Set + diff --git a/deduplicate/trys.js b/deduplicate/trys.js new file mode 100644 index 0000000..3d7183f --- /dev/null +++ b/deduplicate/trys.js @@ -0,0 +1,24 @@ +// const filterArray3 = (array) => array.filter((element, index, array) => (array.indexOf(element) === index)).map(ele => { +// if (ele.indexOf("'") !== -1) { +// let first = ele.slice(0, ele.indexOf("'")) +// console.log(first) +// let middle = "\\'" +// console.log(middle) +// let rest = ele.slice(ele.indexOf("'") + 1) +// console.log(rest) +// console.log(first + middle + rest) +// let alles = first + middle + rest +// console.log(alles) +// return alles +// } else { +// return ele +// } +// }) + + + +// The \ in 'plucker\'s' is a problem. +// tried: +// replace +// \x27 +// String.fromCharCode(92) \ No newline at end of file