.
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const comment = sequelize.define('comment', {
|
||||
activitypub_id: DataTypes.BIGINT,
|
||||
data: DataTypes.JSON
|
||||
}, {});
|
||||
comment.associate = function(models) {
|
||||
}, {})
|
||||
comment.associate = function (models) {
|
||||
comment.belongsTo(models.event)
|
||||
// Event.hasMany(Comment)
|
||||
// Event.hasMany(Comment)
|
||||
// associations can be defined here
|
||||
};
|
||||
return comment;
|
||||
};
|
||||
}
|
||||
return comment
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const event = sequelize.define('event', {
|
||||
title: DataTypes.STRING,
|
||||
slug: DataTypes.STRING,
|
||||
description: DataTypes.TEXT,
|
||||
multidate: DataTypes.BOOLEAN,
|
||||
start_datetime: {
|
||||
start_datetime: {
|
||||
type: DataTypes.DATE,
|
||||
index: true
|
||||
},
|
||||
@@ -16,16 +16,16 @@ module.exports = (sequelize, DataTypes) => {
|
||||
type: DataTypes.BIGINT,
|
||||
index: true
|
||||
}
|
||||
}, {});
|
||||
event.associate = function(models) {
|
||||
}, {})
|
||||
event.associate = function (models) {
|
||||
event.belongsTo(models.place)
|
||||
event.belongsTo(models.user)
|
||||
event.belongsToMany(models.tag, { through: 'event_tags' })
|
||||
event.belongsToMany(models.notification, { through: 'event_notification' })
|
||||
event.hasMany(models.comment)
|
||||
// Tag.belongsToMany(Event, { through: 'tagEvent' })
|
||||
// Tag.belongsToMany(Event, { through: 'tagEvent' })
|
||||
// Event.hasMany(models.Tag)
|
||||
// associations can be defined here
|
||||
};
|
||||
return event;
|
||||
};
|
||||
}
|
||||
return event
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const eventNotification = sequelize.define('eventNotification', {
|
||||
status: {
|
||||
@@ -7,10 +7,10 @@ module.exports = (sequelize, DataTypes) => {
|
||||
defaultValue: 'new',
|
||||
index: true
|
||||
}
|
||||
}, {});
|
||||
|
||||
eventNotification.associate = function(models) {
|
||||
}, {})
|
||||
|
||||
eventNotification.associate = function (models) {
|
||||
// associations can be defined here
|
||||
};
|
||||
return eventNotification;
|
||||
};
|
||||
}
|
||||
return eventNotification
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
'use strict';
|
||||
const argv = require('yargs').argv
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const Sequelize = require('sequelize')
|
||||
const config_path = path.resolve(argv.config || './config.js')
|
||||
const basename = path.basename(__filename)
|
||||
const config = require(config_path).SECRET_CONF.db
|
||||
const db = {}
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const Sequelize = require('sequelize');
|
||||
const basename = path.basename(__filename);
|
||||
const config = require(__dirname + '/../../config.js').SECRET_CONF.db
|
||||
const db = {};
|
||||
|
||||
let sequelize = new Sequelize(config);
|
||||
const sequelize = new Sequelize(config)
|
||||
|
||||
fs
|
||||
.readdirSync(__dirname)
|
||||
.filter(file => {
|
||||
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
|
||||
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js')
|
||||
})
|
||||
.forEach(file => {
|
||||
const model = sequelize['import'](path.join(__dirname, file));
|
||||
db[model.name] = model;
|
||||
});
|
||||
const model = sequelize.import(path.join(__dirname, file))
|
||||
db[model.name] = model
|
||||
})
|
||||
|
||||
Object.keys(db).forEach(modelName => {
|
||||
if (db[modelName].associate) {
|
||||
db[modelName].associate(db);
|
||||
db[modelName].associate(db)
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
db.sequelize = sequelize;
|
||||
db.Sequelize = Sequelize;
|
||||
db.sequelize = sequelize
|
||||
db.Sequelize = Sequelize
|
||||
|
||||
module.exports = db;
|
||||
module.exports = db
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const notification = sequelize.define('notification', {
|
||||
filters: DataTypes.JSON,
|
||||
@@ -8,10 +8,10 @@ module.exports = (sequelize, DataTypes) => {
|
||||
type: DataTypes.ENUM,
|
||||
values: ['mail', 'admin_email', 'mastodon']
|
||||
}
|
||||
}, {});
|
||||
notification.associate = function(models) {
|
||||
notification.belongsToMany(models.event, { through: 'event_notification' })
|
||||
}, {})
|
||||
notification.associate = function (models) {
|
||||
notification.belongsToMany(models.event, { through: 'event_notification' })
|
||||
// associations can be defined here
|
||||
};
|
||||
return notification;
|
||||
};
|
||||
}
|
||||
return notification
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const place = sequelize.define('place', {
|
||||
name: DataTypes.STRING,
|
||||
address: DataTypes.STRING,
|
||||
weigth: DataTypes.INTEGER
|
||||
}, {});
|
||||
}, {})
|
||||
|
||||
place.associate = function(models) {
|
||||
place.associate = function (models) {
|
||||
// associations can be defined here
|
||||
place.hasMany(models.event)
|
||||
};
|
||||
}
|
||||
|
||||
return place;
|
||||
};
|
||||
return place
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const setting = sequelize.define('setting', {
|
||||
key: {
|
||||
key: {
|
||||
type: DataTypes.STRING,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
index: true,
|
||||
index: true
|
||||
},
|
||||
value: DataTypes.JSON
|
||||
}, {});
|
||||
}, {})
|
||||
|
||||
return setting;
|
||||
};
|
||||
return setting
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const tag = sequelize.define('tag', {
|
||||
tag: {
|
||||
@@ -8,12 +8,12 @@ module.exports = (sequelize, DataTypes) => {
|
||||
},
|
||||
weigth: DataTypes.INTEGER,
|
||||
color: DataTypes.STRING
|
||||
}, {});
|
||||
}, {})
|
||||
|
||||
tag.associate = function(models) {
|
||||
tag.associate = function (models) {
|
||||
tag.belongsToMany(models.event, { through: 'event_tags' })
|
||||
// associations can be defined here
|
||||
};
|
||||
}
|
||||
|
||||
return tag;
|
||||
};
|
||||
return tag
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
const bcrypt = require('bcrypt')
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
@@ -14,19 +14,23 @@ module.exports = (sequelize, DataTypes) => {
|
||||
recover_code: DataTypes.STRING,
|
||||
is_admin: DataTypes.BOOLEAN,
|
||||
is_active: DataTypes.BOOLEAN
|
||||
}, {});
|
||||
}, {
|
||||
defaultScope: {
|
||||
exclude: ['password', 'recover_code']
|
||||
}
|
||||
})
|
||||
|
||||
user.associate = function(models) {
|
||||
user.associate = function (models) {
|
||||
// associations can be defined here
|
||||
user.hasMany(models.event)
|
||||
};
|
||||
}
|
||||
|
||||
user.prototype.comparePassword = async function (pwd) {
|
||||
if (!this.password) return false
|
||||
const ret = await bcrypt.compare(pwd, this.password)
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
user.beforeSave(async (user, options) => {
|
||||
if (user.changed('password')) {
|
||||
const salt = await bcrypt.genSalt(10)
|
||||
@@ -35,5 +39,5 @@ module.exports = (sequelize, DataTypes) => {
|
||||
}
|
||||
})
|
||||
|
||||
return user;
|
||||
};
|
||||
return user
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user