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

102 lines
4.8 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 paasRequest = require('./service/paasRequest');
const schedule = require('./schedule')
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)
// 定时任务
schedule(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, ReportSpotCheck, ReportSpotCheckPreview, RoadSpotCheck, RoadSpotCheckPreview,
Village, VillageDistance, RoadSpotCheckChangeLog
} = 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' });
ReportSpotCheckPreview.belongsTo(Department, { foreignKey: 'departmentId', targetKey: 'id' });
Department.hasMany(ReportSpotCheckPreview, { foreignKey: 'departmentId', sourceKey: 'id' });
ReportSpotCheck.belongsTo(Report, { foreignKey: 'reportId', targetKey: 'id' });
Report.hasMany(ReportSpotCheck, { foreignKey: 'reportId', sourceKey: 'id' });
ReportSpotCheck.belongsTo(ReportSpotCheckPreview, { foreignKey: 'prepareId', targetKey: 'id' });
ReportSpotCheckPreview.hasMany(ReportSpotCheck, { foreignKey: 'prepareId', sourceKey: 'id' });
//
RoadSpotCheck.belongsTo(Road, { foreignKey: 'roadId', targetKey: 'id' });
Road.hasMany(RoadSpotCheck, { foreignKey: 'roadId', sourceKey: 'id' });
RoadSpotCheck.belongsTo(RoadSpotCheckPreview, { foreignKey: 'prepareId', targetKey: 'id' });
RoadSpotCheckPreview.hasMany(RoadSpotCheck, { foreignKey: 'prepareId', sourceKey: 'id' });
RoadSpotCheckChangeLog.belongsTo(Road, { foreignKey: 'originRoadId', targetKey: 'id' });
Road.hasMany(RoadSpotCheckChangeLog, { foreignKey: 'originRoadId', sourceKey: 'id' });
RoadSpotCheckChangeLog.belongsTo(Road, { foreignKey: 'changeRoadId', targetKey: 'id' });
Road.hasMany(RoadSpotCheckChangeLog, { foreignKey: 'changeRoadId', sourceKey: 'id' });
RoadSpotCheckChangeLog.belongsTo(RoadSpotCheckPreview, { foreignKey: 'prepareId', targetKey: 'id' });
RoadSpotCheckPreview.hasMany(RoadSpotCheckChangeLog, { foreignKey: 'prepareId', sourceKey: 'id' });
RoadSpotCheckChangeLog.belongsTo(User, { foreignKey: 'userId', targetKey: 'id' });
User.hasMany(RoadSpotCheckChangeLog, { foreignKey: 'userId', sourceKey: 'id' });
VillageDistance.belongsTo(Village, { foreignKey: 'originVillage', targetKey: 'id' });
Village.hasMany(VillageDistance, { foreignKey: 'originVillage', sourceKey: 'id' });
VillageDistance.belongsTo(Village, { foreignKey: 'calcVillage', targetKey: 'id' });
Village.hasMany(VillageDistance, { foreignKey: 'calcVillage', sourceKey: 'id' });
Report.belongsTo(Road, { foreignKey: 'roadId', targetKey: 'id', as: 'road_' });
Road.hasMany(Report, { foreignKey: 'roadId', sourceKey: 'id', as: 'road_' });
};