<commit_before>var tokenCheck = require('../checkToken');
var userService = require('../userService');
var DocumentClient = require('documentdb').DocumentClient;
var client = new DocumentClient(process.env.dbHost, { masterKey: process.env.dbMasterKey });
var docDb = require('../docDbHelper');

module.exports = function (context, req, doc) {
    context.log('Token: ' + req.headers.token);
    let userToken = tokenCheck(req.headers.token, context)
    if (userToken) {
        userService.getUserInformation(userToken.sub, (err, result) => {
            if (err) {
                context.res = {
                    status: 500,
                    body: err
                };
                context.done();
            }
            let participantData = {
                userId: result.user_id,
                userName: result.name,
                value: req.body.value,
                specialNeeds: req.body.special,
                payed: req.body.payed
            }
            if (doc.filter(x => x._self === req.body.eventId).length <= 0) {
                context.res = {
                    status: 404
                };
                context.done();
            }
            if (doc.filter(x => x._self === req.body.eventId)[0].participants.filter(part => part.userId === result.user_id).length <= 0) {
                context.res = {
                    status:'409',
                    body: {
                        'message':'you are not subscribed, dont try to call my api by hand ;) '
                    }
                }
                context.done();
            } else {
                updateItem(req.body.eventId, participantData, (err, result) => {
                    if (err) {
                        context.res = {
                            status: 500,
                            body: err
                        };
                        context.done();
                    } else {
                        context.res = {
                            body: result
                        };
                        context.done();
                    }
                });
            }
        });
    }
    else {
        context.res = {
            status: 401,
            body: 'token was wrong expired or missing'
        };
        context.done();
    }
};

function updateItem(eventId, participant, callback) {
    client.readDocument(eventId, (err, result) => {
        if (err) {
            callback(err);
        }
        else {
            let event = result;
            event.partticipants =  event.participants.splice(event.participants.findIndex(part => part.userId === participant.user_id),1);

            client.replaceDocument(eventId, event, (repErr, repRes) => {
                if (repErr) {
                    callback(repErr);
                }
                else {
                    callback(null, repRes);<commit_msg>Changed unscribed and removed participantmodel<commit_after>var tokenCheck = require('../checkToken');
var userService = require('../userService');
var DocumentClient = require('documentdb').DocumentClient;
var client = new DocumentClient(process.env.dbHost, { masterKey: process.env.dbMasterKey });
var docDb = require('../docDbHelper');

module.exports = function (context, req, doc) {
    context.log('Token: ' + req.headers.token);
    let userToken = tokenCheck(req.headers.token, context)
    if (userToken) {
        userService.getUserInformation(userToken.sub, (err, result) => {
            if (err) {
                context.res = {
                    status: 500,
                    body: err
                };
                context.done();
            }
            context.log(result);
            if (doc.filter(x => x._self === req.body.eventId).length <= 0) {
                context.res = {
                    status: 404
                };
                context.done();
            }
            if (doc.filter(x => x._self === req.body.eventId)[0].participants.filter(part => part.userId === result.user_id).length <= 0) {
                context.res = {
                    status:'409',
                    body: {
                        'message':'you are not subscribed, dont try to call my api by hand ;) '
                    }
                }
                context.done();
            } else {
                updateItem(req.body.eventId, result.user_id, (err, result) => {
                    if (err) {
                        context.res = {
                            status: 500,
                            body: err
                        };
                        context.done();
                    } else {
                        context.res = {
                            body: result
                        };
                        context.done();
                    }
                });
            }
        });
    }
    else {
        context.res = {
            status: 401,
            body: 'token was wrong expired or missing'
        };
        context.done();
    }
};

function updateItem(eventId, userId, callback) {
    client.readDocument(eventId, (err, result) => {
        if (err) {
            callback(err);
        }
        else {
            let event = result;
            event.partticipants =  event.participants.splice(event.participants.findIndex(part => part.userId === userId),1);

            client.replaceDocument(eventId, event, (repErr, repRes) => {
                if (repErr) {
                    callback(repErr);
                }
                else {
                    callback(null, 'unscribed');
{'fraction_non_alphanumeric': 0.1166191155492154, 'fraction_numerical': 0.006776034236804565, 'mean_word_length': 1.1723470178156468, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5592867', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1361, 'n_words': 280}