ecoledirecte.js
Version:
Good-looking client for EcoleDirecte's private API.
60 lines (59 loc) • 1.86 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Message = void 0;
const v3_1 = require("ecoledirecte-api-types/v3");
const util_1 = require("../util");
const classes_1 = require("../classes");
class Message {
constructor(o, user) {
this._user = user;
this.id = o.id;
this.type = o.mtype;
this.read = o.read;
this.transferred = o.transferred;
this.answered = o.answered;
this.to_cc_cci = o.to_cc_cci;
this.subject = o.subject;
this.date = new Date(o.date);
this.to = o.to.map(r => ({
id: r.id,
fullName: r.name,
lastName: r.nom,
firstName: r.prenom,
particle: r.particule,
civility: r.civilite,
role: r.role,
read: r.read,
to_cc_cci: r.to_cc_cci,
}));
this.from = {
id: o.from.id,
fullName: o.from.name,
lastName: o.from.nom,
firstName: o.from.prenom,
particle: o.from.particule,
civility: o.from.civilite,
role: o.from.role,
read: o.from.read,
};
this._raw = o;
}
/**
* @description Fetches the content of the mail
* NEEDS USER
*/
async getContent() {
if (!this._user)
throw new Error("User needs to be provided");
const details = await (0, util_1.makeRequest)({
method: "POST",
path: v3_1.Routes.studentMessage(this._user._raw.id, this.id, {
mode: this.type === "received" ? "destinataire" : "expediteur",
}),
body: { token: this._user.token },
guard: true,
});
return new classes_1.ExpandedBase64(details.data.content);
}
}
exports.Message = Message;