const shared_consts = require('../tools/shared_nodejs');

const express = require('express');
const router = express.Router();

const tools = require('../tools/general');

var server_constants = require('../tools/server_constants');

var {authenticate, auth_default} = require('../middleware/authenticate');

var mongoose = require('mongoose').set('debug', false);
const Subscription = require('../models/subscribers');

const _ = require('lodash');
const {MySkill} = require('../models/myskill');
var {User} = require('../models/user');

const {ObjectId} = require('mongodb');

//GET orders
router.post('/page', authenticate, function(req, res, next) {
  let idSkill = req.body.idSkill;
  let idapp = req.body.idapp;

  return MySkill.getMyRecById(idapp, idSkill).
      then((ris) => {

        if (ris) {
          res.send(ris);
          /*
          const userId = ris.userId;
          return User.getUsernameById(idapp, userId).then((username) =>
          {
            res.send({...ris, username});
          });
          */

        } else {
          res.status(400).send();
        }
      }).catch((e) => {
        console.error('Err', e);
        res.status(400).send(e);
      })


});

module.exports = router;
