idea-toolbox
Version:
IDEA's utility functions
44 lines (43 loc) • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.User = void 0;
const resource_model_1 = require("./resource.model");
/**
* Table: `idea_users`.
*/
class User extends resource_model_1.Resource {
load(x) {
super.load(x);
this.userId = this.clean(x.userId, String);
this.email = this.clean(x.email, String);
this.currentTeamInProjects = {};
if (x.currentTeamInProjects)
for (const project of Object.keys(x.currentTeamInProjects))
if (x.currentTeamInProjects[project])
this.currentTeamInProjects[project] = String(x.currentTeamInProjects[project]);
this.createdAt = this.clean(x.createdAt, d => new Date(d).getTime(), Date.now());
}
safeLoad(newData, safeData) {
super.safeLoad(newData, safeData);
delete this.email; // stored only in Cognito
this.userId = safeData.userId;
this.currentTeamInProjects = safeData.currentTeamInProjects;
this.createdAt = safeData.createdAt;
}
/**
* Get the current team for the user in the selected project.
*/
getCurrentTeamOfProject(project) {
return this.currentTeamInProjects[project] || null;
}
/**
* Set (or reset) the current team for the user in the selected project.
*/
setCurrentTeamOfProject(project, teamId) {
if (teamId)
this.currentTeamInProjects[project] = String(teamId);
else
delete this.currentTeamInProjects[project];
}
}
exports.User = User;