'use strict';
const express = require("express");
const router = express.Router();
const { requireAuthentication } = require("@steedos/auth");
const _ = require('lodash');
const { getCollection } = require("../utils/collection");
const ejs = require('ejs');

router.get('/api/workflow/instances/print/:insId', requireAuthentication, async function (req, res) {
    try {
        const db = {
            instances: await getCollection('instances'),
            instance_tasks: await getCollection('instance_tasks')
        }
        let userSession = req.user;
        const spaceId = userSession.spaceId;
        const userId = userSession.userId;
        const insId = req.params.insId;

        const ins = await db.instances.findOne({_id: insId}, {submitter: 1, outbox_users: 1, state: 1});

        if(!ins){
            res.status(500).send('无效的记录标识')
        }
        const filename = __dirname+'/api_workflow_print.ejs';

        const data = {}

        const options = {}

        ejs.renderFile(filename, data, options, function(err, str){
            if(err){
                console.log(`err`, err)
            }
            res.send(str);
        });
    } catch (error) {
        console.log(error)
        res.status(500).send({ message: error.message });
    }
});
exports.default = router;