四好公路
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.

61 lines
2.4 KiB

3 years ago
'use strict';
const routes = require('./routes');
const fs = require('fs');
const path = require('path');
3 years ago
const authenticator = require('./middlewares/authenticator');
// const apiLog = require('./middlewares/api-log');
const paasRequest = require('./service/paasRequest');
3 years ago
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)
3 years ago
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' });
3 years ago
// 定义外键
Report.belongsTo(User, { foreignKey: 'userId', targetKey: 'id' });
User.hasMany(Report, { foreignKey: 'userId', sourceKey: 'id' });
2 years ago
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' });
3 years ago
};