I need to import my select module in my organization class. My select module as lot of function and i need to access in my organization class.
But the problem is when I try to require my select module from my organization class I have empty object returned. So when I try to use select.somefunction() I have "somefunction is not function". I have another class : User placed in same directory. And when I import select like that :
const select = require("../interfaces/database/select")
.
I have eatch function in select constant...
here you can see my project structure :
├───interfaces
│ ├───database
│ │ delete.js
│ │ insert.js
│ │ select.js
│ │ update.js
│ │
│ └───restAPI
│ scAPI.js
│
├───models
│ Organization.js
│ User.js
│
└───util
logger.js
PostgresHelper.js
so here is my select module:
const log = require("../../util/logger")
const db = require("../../util/PostgresHelper")
const User = require("../../models/User")
const Organization = require("../../models/Organization")
module.exports = {
async getUserFromDiscordID(discordID){
//some code
},
async getUserFromHandle(handle){
//some code
},
async isRegisterFromDiscordID(discordID){
//some code
},
async isRegisterFromHandle(handle){
//some code
},
async getUserLangFromUserID(UserID){
//some code
},
async isOrganizationRegisterFromSID(organizationSID){
//some code
},
async getOrganizationFromSID(organizationSID) {
//some code
},
async getLangFromID(langIDs){
//some code
},
async getLangIDs(lang) {
//some code
}
}
and here is my organization class :
const select = require("../interfaces/database/select")
const scapi = require("../interfaces/restAPI/scAPI")
class Organization {
/**
* @param organizationSID
* @return {Promise<Organization|void>}
*/
static async tryGetOrganizationFromSID(organizationSID){
//let select = require("../interfaces/database/select"); -> when I do that it work but I don't want that
console.log(select)//return empty object
if (await select.isOrganizationRegisterFromSID(organizationSID)){
return await select.getOrganizationFromSID(organizationSID)
}else{
let organizationData = await scapi.getOrganization(organizationSID)
if (organizationData){
return organizationData
}
}
}
}
module.exports = Organization
here is the user class code :
const select = require('../interfaces/database/select')//Here the import work and I have eatch function
const scapi = require("../interfaces/restAPI/scAPI")
class User {
constructor() {
this.discordID = null
this.country =null
this.region = null
this.organizationSID = null
this.organizationRank = null
this.bio = null
this.lang = []
}
/**
* @param {String} discordID
* @return User
*/
static async tryGetUserFromDiscord(discordID){
if (await select.isRegisterFromDiscordID(discordID)){
return await select.getUserFromDiscordID(discordID)
}
}
/**
* @param {String} handle
* @return User
*/
static async tryGetUserFromHandle(handle){
let returnUser = new User()
if (await select.isRegisterFromHandle(handle)){
return await select.getUserFromHandle(handle)
}else {
returnUser = await scapi.getUser(handle)
if(returnUser){
return returnUser
}
}
}
}
module.exports = User