Я пытаюсь реализовать некоторые oop в моей программе javascript, поэтому в основном у меня есть эта структура проекта
src
|_model
| |_Amministratore.js
|_main.js
У меня есть следующий код в Amministratore.js
///Rappresenta un amministratore di sistema
const Storage = require("../PersistanceStorage");
function Amministratore(info) {
this.email = info.email;
this.password = info.password;
this.nome = info.nome;
this.cognome = info.cognome;
this.role = "admin";
this.aggiungiID = function(ID) {
this.ID = ID;
};
//Ritorna il path del nodo
this.path = function() {
return "Admin";
};
//Restituisce la versione memorizzabile nel
this.getUploadableVersion = function() {
return {
[ID]: {
nome: this.nome,
cognome: this.cognome
}
};
};
Теперь в моем main.js у меня есть этот кусок кода:
exports.postAdmin = functions.region(REGION).https.onRequest((req, res) => {
const adminData = req.body;
if (adminData === null || adminData === undefined) {
return res
.status(400)
.send(impacchettaInformazioni(null, "must provide a body!", 400));
}
const admin = new model.Amministratore(adminData);
return admin
.postAmministratore()
.then(function() {
return res
.status(200)
.send(impacchettaInformazioni(null, "Admin created!", 200));
})
.catch(err => {
return rej
.status(500)
.send(impacchettaInformazioni(null, err.message, "500"));
});
});
Но я продолжаю получать эту ошибку:
TypeError: model.Amministratore is not a constructor
at exports.postAdmin.functions.region.https.onRequest (/srv/index.js:311:17)
at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:57:9)
at /worker/worker.js:783:7
at /worker/worker.js:766:11
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickDomainCallback (internal/process/next_tick.js:219:9)
Я что-то упустил? Нужен ли какой-то модуль.export, например, когда я экспортирую некоторые функции в другой файл? Спасибо за помощь.