added data model and user model
This commit is contained in:
50
whatsapp-web.js/src/models/data.js
Normal file
50
whatsapp-web.js/src/models/data.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const { User } = require("../models/user");
|
||||
const { Website } = require("../models/website");
|
||||
|
||||
module.exports.data = new StructuredData();
|
||||
|
||||
class StructuredData {
|
||||
|
||||
constructor() {
|
||||
this.data={};
|
||||
}
|
||||
|
||||
addUser(id){
|
||||
if(this.data[id] != undefined)
|
||||
{
|
||||
this.data[id] = new User(id);
|
||||
return true
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} id
|
||||
* @returns {User}
|
||||
*/
|
||||
getUser(id){
|
||||
return this.data[id];
|
||||
}
|
||||
|
||||
deleteUser(id){
|
||||
if(this.data[id] != undefined)
|
||||
{
|
||||
return delete this.data[id];
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
data structured:
|
||||
data = {
|
||||
<id of user> : <Instance of User>,
|
||||
<id of user> : <Instance of User>
|
||||
}
|
||||
*/
|
||||
43
whatsapp-web.js/src/models/user.js
Normal file
43
whatsapp-web.js/src/models/user.js
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
const {Website} = require('./website');
|
||||
|
||||
class User{
|
||||
|
||||
constructor(id){
|
||||
this.id = id;
|
||||
//uses key value pair to store website
|
||||
//key is the companyName of the website
|
||||
//value is the website itself
|
||||
this.websites = {};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Website} website
|
||||
*/
|
||||
addWebsite(website){
|
||||
if(this.websites[website.companyName] != undefined)
|
||||
{
|
||||
return false;
|
||||
}else{
|
||||
this.websites[website.companyName] = website;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
deleteWebsite(companyName){
|
||||
if(this.websites[companyName] != undefined)
|
||||
{
|
||||
return delete this.websites[companyName];
|
||||
}else{
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
getWebsite(companyName){
|
||||
return this.websites[companyName];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports.User = User;
|
||||
Reference in New Issue
Block a user