-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from CampusTecNode/feature/bookings
Feature/bookings
- Loading branch information
Showing
16 changed files
with
1,090 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${workspaceFolder}\\server.js" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const cron = require('node-cron'); | ||
const { Spaces, Reservations } = require('../data/models'); | ||
const { Op } = require('sequelize'); | ||
|
||
cron.schedule('*/2 * * * *', async () => { // Se ejecuta cada 5 minutos | ||
const now = new Date(); | ||
|
||
// Buscar las reservas que hayan terminado pero que no se hayan marcado como canceladas | ||
const finishedReservations = await Reservations.findAll({ | ||
where: { | ||
EndTime: { [Op.lt]: now }, | ||
DeletedAt: null, | ||
}, | ||
}); | ||
|
||
for (const reservation of finishedReservations) { | ||
// Cambiar el estado del espacio a disponible | ||
const space = await Spaces.findByPk(reservation.SpaceID); | ||
space.Available = true; | ||
await space.save(); | ||
} | ||
|
||
console.log('Checked reservations and updated space availability.'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const { DataTypes } = require('sequelize'); | ||
const sequelize = require('../data/connection'); | ||
|
||
const Reservations = sequelize.define('Reservations', { | ||
ID: { | ||
type: DataTypes.INTEGER, | ||
primaryKey: true, | ||
autoIncrement: true, | ||
}, | ||
UserID: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: 'Users', | ||
key: 'id', | ||
} | ||
}, | ||
SpaceID: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: 'Spaces', | ||
key: 'ID', | ||
} | ||
}, | ||
StartDate: { | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
}, | ||
EndDate: { | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
}, | ||
CreatedAt: { | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: DataTypes.NOW, | ||
}, | ||
CreatedBy: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
defaultValue: 'System', | ||
}, | ||
UpdatedAt: { | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: DataTypes.NOW, | ||
}, | ||
UpdatedBy: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
defaultValue: 'System', | ||
}, | ||
DeletedAt: { | ||
type: DataTypes.DATE, | ||
allowNull: true, | ||
}, | ||
DeletedBy: { | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
} | ||
}, { | ||
tableName: 'Reservations', | ||
timestamps: false, | ||
}); | ||
|
||
module.exports = Reservations; |
Oops, something went wrong.