'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 paasRequest = require('./service/paasRequest'); 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(apiLog(app, opts)); // 实例其他平台请求方法 paasRequest(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) => { require(`./models/${filename}`)(dc) }); const { User, Department, Report, FileType, Road, Files, FileRoad, TaskManage, UserResource, Resource } = 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' }); Files.belongsTo(FileType, { foreignKey: 'fId', targetKey: 'fId' }); FileType.hasMany(Files, { foreignKey: 'fId', targetKey: 'fId' }); // Files.belongsTo(Road, { foreignKey: 'roadId', targetKey: 'id' }); // Road.hasMany(Files, { foreignKey: 'roadId', targetKey: 'id' }); //定义外键 TaskManage.belongsTo(User, { foreignKey: 'userid', targetKey: 'id' }) User.hasMany(TaskManage, { foreignKey: 'userid', targetKey: 'id' }) // TaskManage.belongsTo(Road, { foreignKey: 'roadid', targetKey: 'id' }) Road.hasMany(TaskManage, { foreignKey: 'roadid', targetKey: 'id' }) UserResource.belongsTo(User, { foreignKey: 'userId', targetKey: 'id' }); User.hasMany(UserResource, { foreignKey: 'userId', sourceKey: 'id' }); UserResource.belongsTo(Resource, { foreignKey: 'resourceId', targetKey: 'code' }); Resource.hasMany(UserResource, { foreignKey: 'resourceId', sourceKey: 'code' }); Resource.hasMany(Resource, { foreignKey: 'parentResource', sourceKey: 'code' }); };