|
|
@ -13,86 +13,88 @@ const schedule = require('./schedule') |
|
|
|
// const apiLog = require('./middlewares/api-log');
|
|
|
|
|
|
|
|
module.exports.entry = function (app, router, opts) { |
|
|
|
app.fs.logger.log('info', '[FS-AUTH]', 'Inject auth and api mv into router.'); |
|
|
|
app.fs.logger.log('info', '[FS-AUTH]', 'Inject auth and api mv into router.'); |
|
|
|
|
|
|
|
app.fs.api = app.fs.api || {}; |
|
|
|
app.fs.opts = opts || {}; |
|
|
|
app.fs.utils = app.fs.utils || {}; |
|
|
|
app.fs.api.authAttr = app.fs.api.authAttr || {}; |
|
|
|
app.fs.api.logAttr = app.fs.api.logAttr || {}; |
|
|
|
app.fs.api = app.fs.api || {}; |
|
|
|
app.fs.opts = opts || {}; |
|
|
|
app.fs.utils = app.fs.utils || {}; |
|
|
|
app.fs.api.authAttr = app.fs.api.authAttr || {}; |
|
|
|
app.fs.api.logAttr = app.fs.api.logAttr || {}; |
|
|
|
|
|
|
|
// 顺序固定 ↓
|
|
|
|
//redisConnect(app, opts)
|
|
|
|
socketConect(app, opts) |
|
|
|
// 顺序固定 ↓
|
|
|
|
//redisConnect(app, opts)
|
|
|
|
socketConect(app, opts) |
|
|
|
|
|
|
|
// 实例其他平台请求方法
|
|
|
|
paasRequest(app, opts) |
|
|
|
// 实例其他平台请求方法
|
|
|
|
paasRequest(app, opts) |
|
|
|
|
|
|
|
// clickHouse 数据库 client
|
|
|
|
// clickHouseClient(app, opts)
|
|
|
|
// clickHouse 数据库 client
|
|
|
|
// clickHouseClient(app, opts)
|
|
|
|
|
|
|
|
// 工具类函数
|
|
|
|
utils(app, opts) |
|
|
|
// 工具类函数
|
|
|
|
utils(app, opts) |
|
|
|
|
|
|
|
// 定时任务
|
|
|
|
schedule(app, opts) |
|
|
|
// 定时任务
|
|
|
|
schedule(app, opts) |
|
|
|
|
|
|
|
//鉴权中间件
|
|
|
|
router.use(authenticator(app, opts)); |
|
|
|
//鉴权中间件
|
|
|
|
router.use(authenticator(app, opts)); |
|
|
|
|
|
|
|
// 日志记录
|
|
|
|
// router.use(apiLog(app, opts));
|
|
|
|
// 日志记录
|
|
|
|
// router.use(apiLog(app, opts));
|
|
|
|
|
|
|
|
router = routes(app, router, 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 { |
|
|
|
DataSource, AcquisitionTask, Adapter, User, MetadataDatabase, MetadataFile, MetadataRestapi, AcquisitionLog, ResourceCatalog, |
|
|
|
BusinessMetadataDatabase, BusinessMetadataFile, BusinessMetadataRestapi,ResourceConsumption,BusinessRule,StandardDoc,RestfulApi,RestfulApiRecord |
|
|
|
} = dc.models; |
|
|
|
|
|
|
|
AcquisitionTask.belongsTo(DataSource, { foreignKey: 'dataSourceId', targetKey: 'id' }); |
|
|
|
DataSource.hasMany(AcquisitionTask, { foreignKey: 'dataSourceId', sourceKey: 'id' }); |
|
|
|
AcquisitionLog.belongsTo(AcquisitionTask, { foreignKey: 'task', targetKey: 'id' }); |
|
|
|
AcquisitionTask.hasMany(AcquisitionLog, { foreignKey: 'task', sourceKey: 'id' }); |
|
|
|
DataSource.belongsTo(ResourceCatalog, { foreignKey: 'mountPath', targetKey: 'id' }); |
|
|
|
ResourceCatalog.hasMany(DataSource, { foreignKey: 'mountPath', sourceKey: 'id' }); |
|
|
|
|
|
|
|
DataSource.belongsTo(Adapter, { foreignKey: 'adapterId', targetKey: 'id' }); |
|
|
|
Adapter.hasMany(DataSource, { foreignKey: 'adapterId', sourceKey: 'id' }); |
|
|
|
|
|
|
|
MetadataDatabase.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); |
|
|
|
MetadataFile.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); |
|
|
|
MetadataRestapi.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); |
|
|
|
|
|
|
|
BusinessMetadataDatabase.belongsTo(MetadataDatabase, { foreignKey: 'metadataDatabaseId', targetKey: 'id' }); |
|
|
|
MetadataDatabase.hasMany(BusinessMetadataDatabase, { foreignKey: 'metadataDatabaseId', sourceKey: 'id' }); |
|
|
|
|
|
|
|
BusinessMetadataFile.belongsTo(MetadataFile, { foreignKey: 'metadataFileId', targetKey: 'id' }); |
|
|
|
MetadataFile.hasMany(BusinessMetadataFile, { foreignKey: 'metadataFileId', sourceKey: 'id' }); |
|
|
|
|
|
|
|
BusinessMetadataRestapi.belongsTo(MetadataRestapi, { foreignKey: 'metadataRestapiId', targetKey: 'id' }); |
|
|
|
MetadataRestapi.hasMany(BusinessMetadataRestapi, { foreignKey: 'metadataRestapiId', sourceKey: 'id' }); |
|
|
|
|
|
|
|
BusinessMetadataDatabase.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); |
|
|
|
BusinessMetadataFile.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); |
|
|
|
BusinessMetadataRestapi.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); |
|
|
|
|
|
|
|
ResourceConsumption.belongsTo(User, { foreignKey: 'applyBy', targetKey: 'id' ,as:"applyUser"}); |
|
|
|
ResourceConsumption.belongsTo(User, { foreignKey: 'approveBy', targetKey: 'id',as:'approveUser' }); |
|
|
|
|
|
|
|
// dc = { orm: Sequelize对象, ORM: Sequelize, models: {} }
|
|
|
|
|
|
|
|
// 模型关系摘出来 初始化之后再定义关系才行
|
|
|
|
fs.readdirSync(path.join(__dirname, '/models')).forEach((filename) => { |
|
|
|
require(`./models/${filename}`)(dc) |
|
|
|
}); |
|
|
|
|
|
|
|
const { |
|
|
|
DataSource, AcquisitionTask, Adapter, User, MetadataDatabase, MetadataFile, MetadataRestapi, AcquisitionLog, ResourceCatalog, |
|
|
|
BusinessMetadataDatabase, BusinessMetadataFile, BusinessMetadataRestapi, ResourceConsumption, BusinessRule, StandardDoc, DbStatistics |
|
|
|
, RestfulApi, RestfulApiRecord |
|
|
|
} = dc.models; |
|
|
|
|
|
|
|
AcquisitionTask.belongsTo(DataSource, { foreignKey: 'dataSourceId', targetKey: 'id' }); |
|
|
|
DataSource.hasMany(AcquisitionTask, { foreignKey: 'dataSourceId', sourceKey: 'id' }); |
|
|
|
AcquisitionLog.belongsTo(AcquisitionTask, { foreignKey: 'task', targetKey: 'id' }); |
|
|
|
AcquisitionTask.hasMany(AcquisitionLog, { foreignKey: 'task', sourceKey: 'id' }); |
|
|
|
DataSource.belongsTo(ResourceCatalog, { foreignKey: 'mountPath', targetKey: 'id' }); |
|
|
|
ResourceCatalog.hasMany(DataSource, { foreignKey: 'mountPath', sourceKey: 'id' }); |
|
|
|
|
|
|
|
DataSource.belongsTo(Adapter, { foreignKey: 'adapterId', targetKey: 'id' }); |
|
|
|
Adapter.hasMany(DataSource, { foreignKey: 'adapterId', sourceKey: 'id' }); |
|
|
|
|
|
|
|
MetadataDatabase.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); |
|
|
|
MetadataFile.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); |
|
|
|
MetadataRestapi.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); |
|
|
|
|
|
|
|
BusinessMetadataDatabase.belongsTo(MetadataDatabase, { foreignKey: 'metadataDatabaseId', targetKey: 'id' }); |
|
|
|
MetadataDatabase.hasMany(BusinessMetadataDatabase, { foreignKey: 'metadataDatabaseId', sourceKey: 'id' }); |
|
|
|
|
|
|
|
BusinessMetadataFile.belongsTo(MetadataFile, { foreignKey: 'metadataFileId', targetKey: 'id' }); |
|
|
|
MetadataFile.hasMany(BusinessMetadataFile, { foreignKey: 'metadataFileId', sourceKey: 'id' }); |
|
|
|
|
|
|
|
BusinessMetadataRestapi.belongsTo(MetadataRestapi, { foreignKey: 'metadataRestapiId', targetKey: 'id' }); |
|
|
|
MetadataRestapi.hasMany(BusinessMetadataRestapi, { foreignKey: 'metadataRestapiId', sourceKey: 'id' }); |
|
|
|
|
|
|
|
BusinessMetadataDatabase.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); |
|
|
|
BusinessMetadataFile.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); |
|
|
|
BusinessMetadataRestapi.belongsTo(User, { foreignKey: 'createBy', targetKey: 'id' }); |
|
|
|
|
|
|
|
ResourceConsumption.belongsTo(User, { foreignKey: 'applyBy', targetKey: 'id', as: "applyUser" }); |
|
|
|
ResourceConsumption.belongsTo(User, { foreignKey: 'approveBy', targetKey: 'id', as: 'approveUser' }); |
|
|
|
|
|
|
|
BusinessRule.belongsTo(StandardDoc, { foreignKey: 'ruleBasis', targetKey: 'id' }); |
|
|
|
StandardDoc.hasMany(BusinessRule, { foreignKey: 'ruleBasis', targetKey: 'id' }); |
|
|
|
|
|
|
|
RestfulApi.belongsTo(RestfulApiRecord, { foreignKey: 'restServiceId', targetKey: 'id' }); |
|
|
|
RestfulApiRecord.belongsTo(RestfulApi, { foreignKey: 'restServiceId', targetKey: 'id' }); |
|
|
|
DbStatistics.belongsTo(DataSource, { foreignKey: 'sourceId', targetKey: 'id' }); |
|
|
|
DataSource.hasMany(DbStatistics, { foreignKey: 'sourceId', sourceKey: 'id' }); |
|
|
|
|
|
|
|
RestfulApiRecord.belongsTo(RestfulApi, { foreignKey: 'restServiceId', targetKey: 'id' }); |
|
|
|
}; |
|
|
|