WIP token
This commit is contained in:
65
webserver/database/model/apiKeyModel.js
Normal file
65
webserver/database/model/apiKeyModel.js
Normal file
@ -0,0 +1,65 @@
|
||||
"use strict";
|
||||
const { Sequelize, DataTypes } = require("sequelize");
|
||||
const { sequelize } = require("../mySQL");
|
||||
const { userModel } = require("./userModel");
|
||||
|
||||
//sequelize.sync();
|
||||
const apikeyModel = sequelize.define(
|
||||
"apikey",
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
validate: {
|
||||
isNumeric: true,
|
||||
},
|
||||
},
|
||||
userid: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
validate: {
|
||||
isNumeric: true,
|
||||
},
|
||||
//fk
|
||||
references: {
|
||||
model: userModel,
|
||||
key: "id",
|
||||
},
|
||||
},
|
||||
apikey: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
length: 255,
|
||||
unique: true,
|
||||
validate: {
|
||||
notEmpty: true,
|
||||
len: [1, 255],
|
||||
},
|
||||
},
|
||||
permission: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
length: 255,
|
||||
validate: {
|
||||
notEmpty: true,
|
||||
len: [1, 255],
|
||||
isIn: [["canRead", "canWrite"]],
|
||||
},
|
||||
},
|
||||
createdAt: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
updatedAt: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = { apikeyModel };
|
@ -5,7 +5,7 @@ const { locationModel } = require("./locationModel");
|
||||
const { sensorModel } = require("./sensorModel");
|
||||
const { isJson } = require('../../functions/validateData');
|
||||
|
||||
sequelize.sync();
|
||||
//sequelize.sync();
|
||||
const sensorDataModel = sequelize.define(
|
||||
"sensorData",
|
||||
{
|
||||
|
94
webserver/database/model/userModel.js
Normal file
94
webserver/database/model/userModel.js
Normal file
@ -0,0 +1,94 @@
|
||||
"use strict";
|
||||
const { Sequelize, DataTypes } = require("sequelize");
|
||||
const { sequelize } = require("../mySQL");
|
||||
const {
|
||||
isAlphaNumericWithSpacesAndDash,
|
||||
isAddress,
|
||||
} = require("../../functions/validateData");
|
||||
|
||||
//sequelize.sync();
|
||||
const userModel = sequelize.define(
|
||||
"user",
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
validate: {
|
||||
isNumeric: true,
|
||||
},
|
||||
},
|
||||
username: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
length: 60,
|
||||
validate: {
|
||||
notEmpty: true,
|
||||
len: [1, 60],
|
||||
isAlphaNumericWithSpacesAndDash(value) {
|
||||
if (!isAlphaNumericWithSpacesAndDash(value)) {
|
||||
throw new Error("Invalid characters in username");
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
password: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
length: 255,
|
||||
validate: {
|
||||
notEmpty: true,
|
||||
len: [1, 255],
|
||||
},
|
||||
},
|
||||
email: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
length: 60,
|
||||
unique: true,
|
||||
validate: {
|
||||
notEmpty: true,
|
||||
len: [1, 60],
|
||||
isEmail: true,
|
||||
},
|
||||
},
|
||||
address: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
length: 255,
|
||||
validate: {
|
||||
notEmpty: true,
|
||||
len: [1, 255],
|
||||
isAddress(value) {
|
||||
if (!isAddress(value)) {
|
||||
throw new Error("Invalid address");
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
phone: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
length: 20,
|
||||
validate: {
|
||||
notEmpty: true,
|
||||
len: [1, 20],
|
||||
isNumeric: true,
|
||||
},
|
||||
},
|
||||
//utc time
|
||||
createdAt: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
updatedAt: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
module.exports = { userModel };
|
Reference in New Issue
Block a user