listing slots within current hour
This commit is contained in:
Binary file not shown.
@@ -4,6 +4,11 @@ import bodyParser from "body-parser";
|
|||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
import Database from "better-sqlite3";
|
import Database from "better-sqlite3";
|
||||||
|
|
||||||
|
Date.prototype.addHours= function(h){
|
||||||
|
this.setTime(this.getTime() + (h*60*60*1000));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
const app = e();
|
const app = e();
|
||||||
const port = 3000;
|
const port = 3000;
|
||||||
const db = new Database("./database.db");
|
const db = new Database("./database.db");
|
||||||
@@ -20,7 +25,8 @@ app.get('/currentRooms', (req, res) => {
|
|||||||
// req has no data
|
// req has no data
|
||||||
// res has all room at current time
|
// res has all room at current time
|
||||||
console.log("currentRooms");
|
console.log("currentRooms");
|
||||||
let stmt = db.prepare(`SELECT * FROM TimeSlots`);
|
const today = new Date();
|
||||||
|
let stmt = db.prepare(`SELECT * FROM TimeSlots INNER JOIN Rooms ON Rooms.Id=TimeSlots.Room WHERE TimeEnd BETWEEN '${today.toISOString()}' AND '${today.addHours(1).toISOString()}';`);
|
||||||
let records = stmt.all();
|
let records = stmt.all();
|
||||||
res.status(200).json({records: records});
|
res.status(200).json({records: records});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,10 +18,9 @@ onBeforeMount(async () => {
|
|||||||
</header>
|
</header>
|
||||||
<article v-if="rooms">
|
<article v-if="rooms">
|
||||||
<h2>Free Rooms:</h2>
|
<h2>Free Rooms:</h2>
|
||||||
{{ rooms.records }}
|
|
||||||
<p v-if="rooms.records.length == 0">No free rooms right now</p>
|
<p v-if="rooms.records.length == 0">No free rooms right now</p>
|
||||||
<ul v-for="(slot, index) in rooms.records">
|
<ul v-for="slot in rooms.records">
|
||||||
<li :id="index">{{ slot }}</li>
|
<li>Room: {{ slot.RoomName }}, from {{ slot.TimeStart.toString().split("T")[1] }} til {{ slot.TimeEnd.toString().split("T")[1] }}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</article>
|
</article>
|
||||||
</template>
|
</template>
|
||||||
Reference in New Issue
Block a user