import Worklist from '../../collections/worklist.js';
import { check } from 'meteor/check';

import { Logger } from 'meteor/ostrio:logger';
import { LoggerFile } from 'meteor/ostrio:loggerfile';

var log = new Logger();
(new LoggerFile(log)).enable();

Meteor.publish("worklist", function(devicemap) {

    if (!this.userId) {
        return this.ready();
    }

    const userid = this.userId;
    check(devicemap, String);

    Meteor.settings.enableDebug ? log.debug(`worklistPublisher => start publish worklist `, devicemap, Meteor.user().username) : '';
    return Worklist.find({ _userid: userid, _devicemap: devicemap }, { fields: { _devicemap: 0, _userid: 0 } });
});