/**
 * pm: project management
 * Created by Mai on 2017/3/8.
 */
const BaseController = require("../../common/base/base_controller");
let express = require('express');
let pmController = require('./../controllers/pm_controller');
const baseController = new BaseController();
const systemMiddleware = require('../../main/middleware/index');

module.exports = function (app) {

    app.get('/pm', baseController.init, pmController.index);

    let pmRouter = express.Router();
    pmRouter.get('/getUploadToken', pmController.getUploadToken);
    pmRouter.use(function (req, res, next) {
        if (/\/getNewProjectID/.test(req.originalUrl) ||/\/importProject/.test(req.originalUrl)|| pmController.checkRight(req, res)) {
            next();
        } else {
            res.json({error: 1, message: '对不起，您无权限操作。', data: null});
        }
    });

    /*
     req.body = {data: '{user_id}'}
     */

    pmRouter.post('/prepareInitialData', pmController.prepareInitialData);

    pmRouter.post('/getProjects', pmController.getProjects);
    pmRouter.post('/getAllUnitProjects', pmController.getAllUnitProjects);
    pmRouter.post('/getSummaryInfo', pmController.getSummaryInfo);

    /*
     req.body = {data: '{user_id: user_id, updateData: [{updateType, updateData}]}'}
     data.updateData.updateType: 1 of ['new', 'update', 'delete']
     */
    pmRouter.post('/updateProjects', systemMiddleware.tenderNumberChecking, pmController.updateProjects);
    pmRouter.post('/updateMixDatas', pmController.updateMixDatas);
    pmRouter.post('/moveProject', pmController.moveProject);

    /*
     req.body = {data: '{user_id: user_id, updateData: [{updateType, updateData}]}'}
     data.updateData.updateType: 1 of ['update', 'copy']
     */
    pmRouter.post('/getProjectsByQuery', pmController.getProjectsByQuery);
    pmRouter.post('/copyProjects', systemMiddleware.tenderNumberChecking, pmController.copyProjects);
    pmRouter.post('/renameProject', pmController.rename);
    pmRouter.post('/beforeOpenProject', pmController.beforeOpenProject);
    pmRouter.post('/getProject', pmController.getProject);
    pmRouter.post('/getNewProjectID', pmController.getNewProjectID);
    pmRouter.post('/getUnitFile', pmController.getUnitFileList);
    pmRouter.post('/getFeeRateFile', pmController.getFeeRateFileList);
    pmRouter.post('/updateFiles', pmController.updateFiles);
    pmRouter.post('/defaultSettings', pmController.defaultSettings);
    //GC
    pmRouter.post('/getGCDatas', pmController.getGCDatas);
    pmRouter.post('/recGC', pmController.recGC);
    pmRouter.post('/delGC', pmController.delGC);
    //share
    pmRouter.post('/getReceiveLibList', pmController.getReceiveLibList);
    pmRouter.post('/getProjectShareInfo', pmController.projectShareInfo);
    pmRouter.post('/getInitialShareData', pmController.getInitialShareData);
    pmRouter.post('/getInitialShareLibData', pmController.getInitialShareLibData);
    pmRouter.post('/share', pmController.share);
    pmRouter.post('/shareLib', pmController.shareLib);
    pmRouter.post('/receiveProjects', pmController.receiveProjects);
    pmRouter.post('/changeFile', pmController.changeFile);
    pmRouter.post('/exportProject', pmController.exportProject);
    pmRouter.post('/importProject', pmController.importProject);
    pmRouter.post('/importChongqingProject', pmController.importChongqingProject);
    pmRouter.post('/importExampleProject', pmController.importExampleProject);
    pmRouter.post('/copyConstructionProject',systemMiddleware.tenderNumberChecking,pmController.copyConstructionProject);
    pmRouter.post('/importProcessChecking', pmController.importProcessChecking);
    pmRouter.post('/getBasicInfo', pmController.getBasicInfo);
    pmRouter.post('/getProjectFeature', pmController.getProjectFeature);
    pmRouter.post('/getProjectByGranularity', pmController.getProjectByGranularity);

    app.use('/pm/api', pmRouter);

    let importRouter = express.Router();
    importRouter.post('/getProjectPlaceholder', pmController.getProjectPlaceholder);
    importRouter.post('/importInterface', pmController.importInterface);
    app.use('/pm/import', importRouter);
};


