Skip to content
Open
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
12 changes: 12 additions & 0 deletions builds/readme.md
Original file line number Diff line number Diff line change
@@ -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

69 changes: 69 additions & 0 deletions cars/index.js
Original file line number Diff line number Diff line change
@@ -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 }
// }
// }
// }

// }
26 changes: 26 additions & 0 deletions cars/models/cars.js
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions cars/readme.md
Original file line number Diff line number Diff line change
@@ -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 }
}
}
}
}
21 changes: 21 additions & 0 deletions deduplicate/main.js
Original file line number Diff line number Diff line change
@@ -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

24 changes: 24 additions & 0 deletions deduplicate/trys.js
Original file line number Diff line number Diff line change
@@ -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)