more work!

This commit is contained in:
newtbot
2023-12-31 02:30:49 +08:00
parent 233ebafdcb
commit 234906ada5
18 changed files with 394 additions and 238 deletions

View File

@ -1,45 +0,0 @@
'use strict';
const { Sequelize, DataTypes } = require('sequelize');
const { sequelize } = require("../nySql.js")
const adminUserModel = sequelize.define('adminusers', {
// Model attributes are defined here
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true
},
name: {
type: DataTypes.STRING,
allowNull: true,
length: 255
},
username: {
type: DataTypes.STRING,
allowNull: true,
length: 50
},
email: {
type: DataTypes.STRING,
allowNull: true,
length: 255
},
password: {
type: DataTypes.STRING,
allowNull: true,
length: 255
},
lastLogin: {
type: DataTypes.timestamps,
allowNull: true,
},
jobTitle: {
type: DataTypes.STRING,
allowNull: true,
length: 255
}
},{
timestamps: false, // Disable automatic timestamps
});
module.exports = { adminUserModel }

View File

@ -3,7 +3,7 @@ const { Sequelize, DataTypes } = require("sequelize");
const { sequelize } = require("../mySQL");
sequelize.sync();
//sequelize.sync();
const api_log_Model = sequelize.define("api-logs",{
// Model attributes are defined here
id: {

View File

@ -2,7 +2,7 @@
const { Sequelize, DataTypes } = require("sequelize");
const { sequelize } = require("../mySQL");
sequelize.sync();
//sequelize.sync();
const locationModel = sequelize.define(
"location",
{

View File

@ -0,0 +1,54 @@
"use strict";
const { Sequelize, DataTypes } = require("sequelize");
const { sequelize } = require("../mySQL");
const { locationModel } = require("./locationModel");
const { sensorModel } = require("./sensorModel");
//sequelize.sync();
const sensorDataModel = sequelize.define("sensorData",
{
id: {
type: DataTypes.INTEGER,
allowNull: true,
primaryKey: true,
autoIncrement: true,
},
id_sensor: {
type: DataTypes.INTEGER,
allowNull: false,
length: 100,
//FK
references: {
model: sensorModel,
key: 'id'
}
},
id_location: {
type: DataTypes.INTEGER,
allowNull: false,
length: 100,
//FK
references: {
model: locationModel,
key: 'id'
}
},
Sensordata: {
type: DataTypes.JSON,
allowNull: false,
},
createdAt: {
type: DataTypes.DATE,
allowNull: true,
},
updatedAt: {
type: DataTypes.DATE,
allowNull: true,
},
},
{
timestamps: true,
}
);
module.exports = { sensorDataModel };

View File

@ -0,0 +1,54 @@
"use strict";
const { Sequelize, DataTypes } = require("sequelize");
const { sequelize } = require("../mySQL");
const { locationModel } = require("./locationModel");
//sequelize.sync();
const sensorModel = sequelize.define("sensors",
{
id: {
type: DataTypes.INTEGER,
allowNull: true,
primaryKey: true,
autoIncrement: true,
},
sensortype: {
type: DataTypes.STRING,
allowNull: false,
length: 10,
},
added_by: {
type: DataTypes.STRING,
allowNull: false,
length: 10,
},
description: {
type: DataTypes.STRING,
allowNull: true,
length: 100,
},
location: {
type: DataTypes.INTEGER,
allowNull: true,
length: 100,
//one to many relationship
references: {
model: locationModel,
key: 'id'
}
},
createdAt: {
type: DataTypes.DATE,
allowNull: true,
},
updatedAt: {
type: DataTypes.DATE,
allowNull: true,
},
},
{
timestamps: true,
}
);
module.exports = { sensorModel };

View File

@ -1,40 +0,0 @@
'use strict';
const { Sequelize, DataTypes } = require('sequelize');
const { sequelize } = require("../mySql.js");
const userModel = sequelize.define('users', {
// Model attributes are defined here
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true
},
name: {
type: DataTypes.STRING,
allowNull: true,
length: 255
},
username: {
type: DataTypes.STRING,
allowNull: true,
length: 50
},
email: {
type: DataTypes.STRING,
allowNull: true,
length: 255
},
password: {
type: DataTypes.STRING,
allowNull: true,
length: 255
},
lastLogin: {
type: DataTypes.timestamps,
allowNull: true,
}
},{
timestamps: false, // Disable automatic timestamps
});
module.exports = { userModel }