add types for linting

This commit is contained in:
b1ek 2023-02-22 23:54:35 +10:00
parent 7294210821
commit 8d29d4d395
Signed by: blek
GPG Key ID: 14546221E3595D0C
4 changed files with 140 additions and 17 deletions

54
models/article.js Normal file
View File

@ -0,0 +1,54 @@
const { Model } = require('sequelize');
class Article extends Model {
}
let init = (sequelize, DataTypes) => {
let article = Article.init({
id: {
type: DataTypes.BIGINT(11),
primaryKey: true,
autoIncrement: true,
allowNull: false
},
title: {
type: DataTypes.TEXT,
allowNull: false
},
shortText: {
type: DataTypes.TEXT,
allowNull: false
},
body: {
type: DataTypes.TEXT,
allowNull: false
},
submitted: {
type: DataTypes.BIGINT,
allowNull: false
},
edited: {
type: DataTypes.BIGINT,
allowNull: false
},
submitter: {
type: DataTypes.BIGINT,
allowNull: false
},
gpgsign: {
type: DataTypes.TEXT,
allowNull: true
}
}, {
sequelize,
modelName: 'Article',
tableName: 'articles'
})
article.class = Article;
return article;
}
init.class = Article;
module.exports = init;

View File

@ -1,9 +1,6 @@
'use strict';
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class Guestbook extends Model {
const { Model } = require('sequelize');
class Guestbook extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
@ -12,8 +9,10 @@ module.exports = (sequelize, DataTypes) => {
static associate(models) {
// define association here
}
}
Guestbook.init({
}
const init = (sequelize, DataTypes) => {
let model = Guestbook.init({
id: {
type: DataTypes.BIGINT(11),
primaryKey: true,
@ -49,5 +48,8 @@ module.exports = (sequelize, DataTypes) => {
modelName: 'Guestbook',
tableName: 'guestbook'
});
return Guestbook;
return model;
};
init.class = Guestbook;
return init;

View File

@ -9,6 +9,19 @@ const process = require('process');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'production';
let config = require(__dirname + '/../config/config.json')[env];
class Models {
sequelize = Sequelize
Sequelize = Sequelize
User = require('./user').class
Article = require('./article').class
Guestbook = require('./guestbook').class
}
/**
* @type Models
*/
const db = {};
const {

54
models/user.js Normal file
View File

@ -0,0 +1,54 @@
const { Model } = require('sequelize');
class User extends Model {
}
/**
*
* @param {import('sequelize').Sequelize} sequelize
* @param {import('sequelize').DataTypes} DataTypes
*/
const init = (sequelize, DataTypes) => {
let user = User.init({
id: {
type: DataTypes.BIGINT,
primaryKey: true,
autoIncrement: true,
allowNull: false
},
login: {
type: DataTypes.TEXT,
allowNull: false
},
pass: {
type: DataTypes.TEXT,
allowNull: false
},
totp: {
type: DataTypes.TEXT,
allowNull: true
},
totpRec: {
type: DataTypes.TEXT,
allowNull: true
},
email: {
type: DataTypes.TEXT,
allowNull: false
},
gpgkey: {
type: DataTypes.TEXT,
allowNull: false
}
}, {
sequelize,
tableName: 'users',
tableName: 'users'
});
return user;
}
init.class = User;
module.exports = init;