migrated database folder to my own folders

This commit is contained in:
newtbot
2024-01-14 17:49:44 +08:00
parent c00a57d5f6
commit d9e028d300
14 changed files with 22 additions and 28 deletions

View File

@ -0,0 +1,77 @@
"use strict";
const { Sequelize, DataTypes } = require("sequelize");
const { sequelize } = require("../mySQL");
const { locationModel } = require("./locationModel");
const { sensorModel } = require("./sensorModel");
const { isJson } = require('../../functions/validateData');
sequelize.sync();
const sensorDataModel = sequelize.define(
"sensorData",
{
id: {
type: DataTypes.INTEGER,
allowNull: true,
primaryKey: true,
autoIncrement: true,
unique: true,
validate: {
isNumeric: true,
notEmpty: true,
},
},
sensorid: {
type: DataTypes.INTEGER,
allowNull: false,
length: 100,
//FK
references: {
model: sensorModel,
key: "id",
},
validate: {
isNumeric: true,
notEmpty: true,
},
},
locationid: {
type: DataTypes.INTEGER,
allowNull: false,
length: 100,
//FK
references: {
model: locationModel,
key: "id",
},
validate: {
isNumeric: true,
notEmpty: true,
},
},
measurement: {
type: DataTypes.JSON,
allowNull: false,
validate: {
notEmpty: true,
isJson(value)
{
if (isJson(value) !== true)
throw new Error("sensordata must be a JSON");
},
},
},
createdAt: {
type: DataTypes.DATE,
allowNull: true,
},
updatedAt: {
type: DataTypes.DATE,
allowNull: true,
},
},
{
timestamps: true,
}
);
module.exports = { sensorDataModel };