You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.4 KiB
38 lines
1.4 KiB
'use strict';
|
|
|
|
const routes = require('./routes');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const authenticator = require('./middlewares/authenticator');
|
|
// const apiLog = require('./middlewares/api-log');
|
|
const businessRest = require('./middlewares/business-rest');
|
|
|
|
module.exports.entry = function (app, router, opts) {
|
|
app.fs.logger.log('info', '[FS-AUTH]', 'Inject auth and api mv into router.');
|
|
|
|
app.fs.api = app.fs.api || {};
|
|
app.fs.api.authAttr = app.fs.api.authAttr || {};
|
|
app.fs.api.logAttr = app.fs.api.logAttr || {};
|
|
|
|
router.use(authenticator(app, opts));
|
|
router.use(businessRest(app, router, opts));
|
|
// router.use(apiLog(app, opts));
|
|
|
|
router = routes(app, router, opts);
|
|
};
|
|
|
|
module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Sequelize, models: {} }
|
|
fs.readdirSync(path.join(__dirname, '/models')).forEach((filename) => {
|
|
console.log(filename);
|
|
require(`./models/${filename}`)(dc)
|
|
});
|
|
|
|
const { User, Department, Report } = dc.models;
|
|
// 定义外键
|
|
User.belongsTo(Department, { foreignKey: 'departmentId', targetKey: 'id' });
|
|
Department.hasMany(User, { foreignKey: 'departmentId', sourceKey: 'id' });
|
|
|
|
// 定义外键
|
|
Report.belongsTo(User, { foreignKey: 'userId', targetKey: 'id' });
|
|
User.hasMany(Report, { foreignKey: 'userId', sourceKey: 'id' });
|
|
};
|
|
|