<commit_before>'use strict';

import * as models from "../../../../models/models";
import * as _ from 'lodash';
import * as express from 'express';
const MicrosoftGraph = require('@microsoft/microsoft-graph-client');

// https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/group_post_channels
// Scopes: Group.ReadWrite.All

// Function to retrieve channel list via the Microsoft Graph API
function list_channels(req: express.Request, res: express.Response) {
    let token = _.get<string>(req, 'headers.token', undefined);
    console.log("TOKEN: ", token)
    let graph_client = MicrosoftGraph.Client.init({
        authProvider: (done: any) => {
            if (token) {
                done(null, token); //first parameter takes an error if you can't get an access token
            } else {
                done("Error: User token required", null);
            }
        }
    });

    graph_client
        .api('groups/{group_id}/channels'.replace('{group_id}', req.params['id']))
        .version("beta") //optional, but recommeded to have before query params
        // .select("displayName")
        .get()
        .then((graph_res: any) => {
            // Filter out extraneous info
            console.log("Success!!!");
            let val = graph_res.body.value;
            for (let i in val) {
                val[i] = models.GraphChannelInfo.fromObj(val[i]);
            }
            res.json(val);
        }).catch((err: any) => {
            console.log("auth failure")
            res.send(err);
        });
};

// Function to retrieve channel list via the Microsoft Graph API
function create_channel(req: express.Request, res: express.Response) {
    let token = _.get<string>(req, 'headers.token', undefined);

    let graph_client = MicrosoftGraph.Client.init({
        authProvider: (done: any) => {
            done(null, token); //first parameter takes an error if you can't get an access token
        }
    });

    graph_client
        .api('groups/{group_id}/channels'.replace('{group_id}', req.params['id']))
        .version("beta") //optional, but recommeded to have before query params
        // .select("displayName")
        .post(req.body)
        .then((graph_res: any) => {
            // Filter out extraneous info<commit_msg>fixed list_channels function<commit_after>'use strict';

import * as models from "../../../../models/models";
import * as _ from 'lodash';
import * as express from 'express';
const MicrosoftGraph = require('@microsoft/microsoft-graph-client');

// https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/group_post_channels
// Scopes: Group.ReadWrite.All

// Function to retrieve channel list via the Microsoft Graph API
function list_channels(req: express.Request, res: express.Response) {
    let token = _.get<string>(req, 'headers.token', undefined);
    console.log("TOKEN: ", token)
    let graph_client = MicrosoftGraph.Client.init({
        authProvider: (done: any) => {
            if (token) {
                done(null, token); //first parameter takes an error if you can't get an access token
            } else {
                done("Error: User token required", null);
            }
        }
    });

    graph_client
        .api('groups/{group_id}/channels'.replace('{group_id}', req.params['id']))
        .version("beta") //optional, but recommeded to have before query params
        // .select("displayName")
        .get()
        .then((graph_res: any) => {
            // Filter out extraneous info
            console.log("Success!!!");
            let val = graph_res.value;
            for (let i in val) {
                val[i] = models.GraphChannelInfo.fromObj(val[i]);
            }
            res.json(val);
        }).catch((err: any) => {
            console.log("auth failure")
            res.send(err);
        });
};

// Function to create a channel via the Microsoft Graph API
function create_channel(req: express.Request, res: express.Response) {
    let token = _.get<string>(req, 'headers.token', undefined);

    let graph_client = MicrosoftGraph.Client.init({
        authProvider: (done: any) => {
            done(null, token); //first parameter takes an error if you can't get an access token
        }
    });

    graph_client
        .api('groups/{group_id}/channels'.replace('{group_id}', req.params['id']))
        .version("beta") //optional, but recommeded to have before query params
        // .select("displayName")
        .post(req.body)
        .then((graph_res: any) => {
            // Filter out extraneous info
{'fraction_non_alphanumeric': 0.14298188168522158, 'fraction_numerical': 0.0, 'mean_word_length': 2.3494152046783627, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '2224278', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1250, 'n_words': 339}