I'm trying to call a Javascriptcript method in a class from another class and I get an error
error
{ error: 'slackService.getAccessData is not a function' }
In the slackController.js below I called the method from slackServices.js saying
slackService.getAccessData(code)
Find my slackcontroller.js below
import slackService from "../services/SlackService.js"
class SlackController {
async handleCallback(req, res) {
try {
const code = req.query.code;
console.log(code);
if (code) {
const { email, userData } = await slackService.getAccessData(code);
const { slack_user_id } = userData;
res.redirect("/")
} else {
res.redirect("/");
}
} catch (e) {
console.log("error")
console.log({error: e.message});
res.json({ error: e.message });
}
} }
export default new SlackController();
find my slackService.js below
import Client from './WebClient.js';
import config from '../config/slack.js';
import { createReadStream } from 'fs';
class SlackService {
async getAccessData(code) {
const data = await this.getAccessToken(code);
const user = await this.getUserInfo({
token: data.access_token, user_id: data.authed_user.id
});
console.log(data, user);
return this.format(data, user);
}
async getUserInfo({ token, user_id }) {
const wc = new Client(token);
const { user } = await wc.users.info({ user: user_id });
return user;
}
async getAccessToken (code) {
const wc = new Client();
// return await wc.accessToken(config(code));
return await wc.accessToken(code);
}
}
}
export default SlackService;