added code to add new item for sale by seller
This commit is contained in:
parent
88a9fb40a9
commit
4d9182ae65
@ -4,7 +4,6 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
<link rel="stylesheet" href="css/main.css">
|
|
||||||
<link href="https://fonts.googleapis.com/css?family=Merriweather:700|Roboto:300,400,500,700&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css?family=Merriweather:700|Roboto:300,400,500,700&display=swap" rel="stylesheet">
|
||||||
<title>City e-commerce</title>
|
<title>City e-commerce</title>
|
||||||
<style>* {
|
<style>* {
|
||||||
@ -1127,6 +1126,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script id="init_lib">
|
<script id="init_lib">
|
||||||
//All util libraries required for Standard operations (DO NOT EDIT ANY)
|
//All util libraries required for Standard operations (DO NOT EDIT ANY)
|
||||||
|
|
||||||
@ -8104,6 +8104,7 @@
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script id="floCrypto">
|
<script id="floCrypto">
|
||||||
/* FLO Crypto Operators*/
|
/* FLO Crypto Operators*/
|
||||||
const floCrypto = {
|
const floCrypto = {
|
||||||
@ -8634,48 +8635,48 @@
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
getInnerNodes: function (flo_addr1, flo_addr2, KB = this.supernodeKBucket) {
|
getInnerNodes: function(flo_addr1, flo_addr2, KB = this.supernodeKBucket){
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let kArrayFloIds = KB.toArray().map(k => k.floID);
|
let kArrayFloIds = KB.toArray().map(k => k.floID);
|
||||||
var innerNodes = []
|
var innerNodes = []
|
||||||
if (kArrayFloIds.includes(flo_addr1) && kArrayFloIds.includes(flo_addr2)) {
|
if(kArrayFloIds.includes(flo_addr1) && kArrayFloIds.includes(flo_addr2)){
|
||||||
for (var i = kArrayFloIds.indexOf(flo_addr1); i != flo_addr2; i++) {
|
for(var i = kArrayFloIds.indexOf(flo_addr1); i!= flo_addr2; i++){
|
||||||
if (i >= kArrayFloIds.length)
|
if(i >= kArrayFloIds.length)
|
||||||
i = -1
|
i = -1
|
||||||
else
|
else
|
||||||
innerNodes.push(kArrayFloIds[i])
|
innerNodes.push(kArrayFloIds[i])
|
||||||
}
|
}
|
||||||
resolve(innerNodes)
|
resolve(innerNodes)
|
||||||
} else
|
}else
|
||||||
reject('Given nodes are not in KBucket')
|
reject('Given nodes are not in KBucket')
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getOuterNodes: function (flo_addr1, flo_addr2, KB = this.supernodeKBucket) {
|
getOuterNodes: function(flo_addr1, flo_addr2, KB = this.supernodeKBucket){
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let kArrayFloIds = KB.toArray().map(k => k.floID);
|
let kArrayFloIds = KB.toArray().map(k => k.floID);
|
||||||
var outterNodes = []
|
var outterNodes = []
|
||||||
if (kArrayFloIds.includes(flo_addr1) && kArrayFloIds.includes(flo_addr2)) {
|
if(kArrayFloIds.includes(flo_addr1) && kArrayFloIds.includes(flo_addr2)){
|
||||||
for (var i = kArrayFloIds.indexOf(flo_addr2); i != flo_addr1; i++) {
|
for(var i = kArrayFloIds.indexOf(flo_addr2); i!= flo_addr1; i++){
|
||||||
if (i >= kArrayFloIds.length)
|
if(i >= kArrayFloIds.length)
|
||||||
i = -1
|
i = -1
|
||||||
else
|
else
|
||||||
outterNodes.push(kArrayFloIds[i])
|
outterNodes.push(kArrayFloIds[i])
|
||||||
}
|
}
|
||||||
resolve(outterNodes)
|
resolve(outterNodes)
|
||||||
} else
|
}else
|
||||||
reject('Given nodes are not in KBucket')
|
reject('Given nodes are not in KBucket')
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getPrevSupernode: function (flo_addr, n = 1, KB = this.supernodeKBucket) {
|
getPrevSupernode: function(flo_addr, n = 1, KB = this.supernodeKBucket){
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
let kArrayFloIds = KB.toArray().map(k => k.floID);
|
let kArrayFloIds = KB.toArray().map(k => k.floID);
|
||||||
let pos = kArrayFloIds.indexOf(flo_addr)
|
let pos = kArrayFloIds.indexOf(flo_addr)
|
||||||
var prevSupernode = []
|
var prevSupernode = []
|
||||||
for (var i = 1; i <= n; i++) {
|
for(var i = 1; i <= n; i++){
|
||||||
if (pos - i < 0)
|
if(pos - i < 0)
|
||||||
var prev = pos - i + kArrayFloIds.length
|
var prev = pos - i + kArrayFloIds.length
|
||||||
else
|
else
|
||||||
var prev = pos - i
|
var prev = pos - i
|
||||||
@ -8688,14 +8689,14 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getNextSupernode: function (flo_addr, n = 1, KB = this.supernodeKBucket) {
|
getNextSupernode: function(flo_addr, n = 1, KB = this.supernodeKBucket){
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
let kArrayFloIds = KB.toArray().map(k => k.floID);
|
let kArrayFloIds = KB.toArray().map(k => k.floID);
|
||||||
let pos = kArrayFloIds.indexOf(flo_addr)
|
let pos = kArrayFloIds.indexOf(flo_addr)
|
||||||
var nextSupernode = []
|
var nextSupernode = []
|
||||||
for (var i = 1; i <= n; i++) {
|
for(var i = 1; i <= n; i++){
|
||||||
if (pos + i >= kArrayFloIds.length)
|
if(pos + i >= kArrayFloIds.length)
|
||||||
var next = pos + i - kArrayFloIds.length
|
var next = pos + i - kArrayFloIds.length
|
||||||
else
|
else
|
||||||
var next = pos + i
|
var next = pos + i
|
||||||
@ -8724,28 +8725,32 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
sendDataToSN(data, snfloID) {
|
sendDataToSN(data, snfloID){
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
console.log(snfloID)
|
console.log(snfloID)
|
||||||
var websocket = new WebSocket("wss://" + floGlobals.supernodes[snfloID].uri + "/ws");
|
var websocket = new WebSocket("wss://" + floGlobals.supernodes[snfloID].uri + "/ws");
|
||||||
websocket.onmessage = (evt => {
|
websocket.onmessage = (evt => {
|
||||||
if (evt.data == '$+') {
|
if(evt.data == '$+'){
|
||||||
websocket.send(data);
|
websocket.send(data);
|
||||||
resolve(`Data sent to supernode : ${snfloID}`);
|
resolve(`Data sent to supernode : ${snfloID}`);
|
||||||
} else if (evt.data == '$-') {
|
}else if(evt.data == '$-'){
|
||||||
this.kBucket.getNextSupernode(snfloID)
|
this.kBucket.getNextSupernode(snfloID).then(nextNode => {
|
||||||
.then(nextNode => this.sendDataToSN(data, nextNode[0]))
|
this.sendDataToSN(data, nextNode[0])
|
||||||
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
} else {
|
}).catch(error => reject(error))
|
||||||
|
}else{
|
||||||
console.log(evt.data)
|
console.log(evt.data)
|
||||||
reject(evt.data)
|
reject(evt.data)
|
||||||
}
|
}
|
||||||
websocket.close();
|
websocket.close();
|
||||||
})
|
})
|
||||||
websocket.onerror = (evt) => {
|
websocket.onerror = (evt) => {
|
||||||
this.kBucket.getNextSupernode(snfloID)
|
this.kBucket.getNextSupernode(snfloID).then(nextNode => {
|
||||||
.then(nextNode => this.sendDataToSN(data, nextNode[0]))
|
this.sendDataToSN(data, nextNode[0])
|
||||||
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
|
}).catch(error => reject(error))
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -8764,26 +8769,30 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
requestDataFromSN(request, snfloID) {
|
requestDataFromSN(request, snfloID){
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var websocket = new WebSocket("wss://" + floGlobals.supernodes[snfloID].uri + "/ws");
|
var websocket = new WebSocket("wss://" + floGlobals.supernodes[snfloID].uri + "/ws");
|
||||||
websocket.onmessage = (evt => {
|
websocket.onmessage = (evt => {
|
||||||
if (evt.data == '$+') {
|
if(evt.data == '$+'){
|
||||||
websocket.send(`?${request}`);
|
websocket.send(`?${request}`);
|
||||||
} else if (evt.data == '$-') {
|
}else if(evt.data == '$-'){
|
||||||
this.kBucket.getNextSupernode(snfloID)
|
this.kBucket.getNextSupernode(snfloID).then(nextNode => {
|
||||||
.then(nextNode => this.requestDataFromSN(request, nextNode[0]))
|
this.requestDataFromSN(request, nextNode[0])
|
||||||
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
|
}).catch(error => reject(error))
|
||||||
websocket.close()
|
websocket.close()
|
||||||
} else {
|
}else{
|
||||||
resolve(evt.data);
|
resolve(evt.data);
|
||||||
websocket.close();
|
websocket.close();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
websocket.onerror = (evt) => {
|
websocket.onerror = (evt) => {
|
||||||
this.kBucket.getNextSupernode(snfloID)
|
this.kBucket.getNextSupernode(snfloID).then(nextNode => {
|
||||||
.then(nextNode => this.requestDataFromSN(request, nextNode[0]))
|
this.requestDataFromSN(request, nextNode[0])
|
||||||
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
|
}).catch(error => reject(error))
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -9560,46 +9569,7 @@
|
|||||||
appObjects: {},
|
appObjects: {},
|
||||||
vectorClock: {},
|
vectorClock: {},
|
||||||
generalData: {},
|
generalData: {},
|
||||||
generalVC: {},
|
generalVC: {}
|
||||||
/* ecommerce app */
|
|
||||||
// general purposes datastores
|
|
||||||
myInfo: {
|
|
||||||
indexes: {pubKey: null}
|
|
||||||
},
|
|
||||||
live_orders: {
|
|
||||||
indexes: {
|
|
||||||
orderId: null,
|
|
||||||
productCategory: null,
|
|
||||||
dateOfOrder: null,
|
|
||||||
status: null,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
my_orders_history: {
|
|
||||||
indexes: {
|
|
||||||
orderId: null,
|
|
||||||
productCategory: null,
|
|
||||||
dateOfOrder: null,
|
|
||||||
status: null,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// for Seller view
|
|
||||||
sellerProducts: {
|
|
||||||
indexes: {
|
|
||||||
productFloId: null,
|
|
||||||
productCategory: null,
|
|
||||||
productType: null,
|
|
||||||
status: null,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// for Buyer view
|
|
||||||
my_search_history: {
|
|
||||||
indexes: {
|
|
||||||
productCategory: null,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//add other given objectStores
|
//add other given objectStores
|
||||||
for (o in this.appObs)
|
for (o in this.appObs)
|
||||||
@ -9837,25 +9807,22 @@
|
|||||||
|
|
||||||
reactor.registerEvent("startUpErrorLog");
|
reactor.registerEvent("startUpErrorLog");
|
||||||
reactor.addEventListener("startUpErrorLog", log => console.error(log))
|
reactor.addEventListener("startUpErrorLog", log => console.error(log))
|
||||||
reactor.addEventListener("startUpErrorLog", log => showMessage(log))
|
reactor.addEventListener("startUpErrorLog", log => console.showMessage(log))
|
||||||
|
|
||||||
function onLoadStartUp() {
|
function onLoadStartUp() {
|
||||||
showMessage("Starting the app! Please Wait!")
|
showMessage("Starting the app! Please Wait!")
|
||||||
floDapps.launchStartUp().then(result => {
|
floDapps.launchStartUp().then(result => {
|
||||||
|
|
||||||
// identify and unlock user functions
|
|
||||||
ecommerce.actions.doShreeGanesh();
|
|
||||||
|
|
||||||
console.log(result)
|
console.log(result)
|
||||||
showMessage(result)
|
showMessage(result)
|
||||||
showMessage(`Welcome ${myFloID}`)
|
showMessage(`Welcome ${myFloID}`)
|
||||||
|
ecommerce.actions.doShreeGanesh();
|
||||||
}).catch(error => console.error(error))
|
}).catch(error => console.error(error))
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
function system_message(msg='', type='') {
|
function showMessage(msg='', type='') {
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9970,8 +9937,9 @@
|
|||||||
|
|
||||||
parse_flo_comments: async function() {
|
parse_flo_comments: async function() {
|
||||||
text = `masterFLOPubKey=03EA5E2CAB18DA585400D6EC569438D415FAF200528E05D0E2B9BEAA2B5C3DCA90
|
text = `masterFLOPubKey=03EA5E2CAB18DA585400D6EC569438D415FAF200528E05D0E2B9BEAA2B5C3DCA90
|
||||||
#!#SUBJECT='TEST_ECOMMERCE'
|
#!#SUBJECT=TEST_ECOMMERCE_4
|
||||||
#!#DATA_TYPE=EC1
|
#!#DATA_TYPE=EC4
|
||||||
|
#!#CITY=Ranchi
|
||||||
#!#product_categories = Electronics,Clothes & Accessories,Home Appliances
|
#!#product_categories = Electronics,Clothes & Accessories,Home Appliances
|
||||||
#!#cashiers=
|
#!#cashiers=
|
||||||
{
|
{
|
||||||
@ -10063,7 +10031,8 @@
|
|||||||
floAssetsArray[1].trim() !== ""
|
floAssetsArray[1].trim() !== ""
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
floAssetsArray.map(function(assets_string) {
|
for (const assets_string of floAssetsArray) {
|
||||||
|
|
||||||
let k = assets_string.split("=");
|
let k = assets_string.split("=");
|
||||||
|
|
||||||
if (k[1].indexOf(",") > 0 && k[1].indexOf("{") == -1) {
|
if (k[1].indexOf(",") > 0 && k[1].indexOf("{") == -1) {
|
||||||
@ -10080,7 +10049,9 @@
|
|||||||
k[1] = JSON.parse(k[1].replace(/ /g, ""));
|
k[1] = JSON.parse(k[1].replace(/ /g, ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.defineProperty(
|
if(typeof ecommerce.master_configurations!=="object") ecommerce.master_configurations = {};
|
||||||
|
|
||||||
|
Object.defineProperty(
|
||||||
ecommerce.master_configurations,
|
ecommerce.master_configurations,
|
||||||
k[0],
|
k[0],
|
||||||
{
|
{
|
||||||
@ -10090,7 +10061,7 @@
|
|||||||
enumerable: true
|
enumerable: true
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
deepFreeze(ecommerce.master_configurations);
|
deepFreeze(ecommerce.master_configurations);
|
||||||
console.log(ecommerce);
|
console.log(ecommerce);
|
||||||
return ecommerce;
|
return ecommerce;
|
||||||
@ -10110,19 +10081,49 @@
|
|||||||
await this.fetch_configs();
|
await this.fetch_configs();
|
||||||
|
|
||||||
// Identify logged in user as either buyer, seller, cashier or courier
|
// Identify logged in user as either buyer, seller, cashier or courier
|
||||||
const loggedInUser = new ecommerce.users.current_user({
|
ecommerce.loggedInUser = new ecommerce.users.current_user({
|
||||||
flo_id: myFloID,
|
flo_id: myFloID,
|
||||||
});
|
});
|
||||||
|
|
||||||
deepFreeze(loggedInUser.user_info);
|
deepFreeze(ecommerce.loggedInUser.user_info);
|
||||||
|
|
||||||
|
const LIVE_USER = ecommerce.loggedInUser;
|
||||||
|
|
||||||
|
if(LIVE_USER.user_info.user_role==='BUYER') {
|
||||||
|
LIVE_USER.user_info.set_delivery_receiving_address();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.retrieveLatestContent();
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
retrieveLatestContent: async function (receiverID = floGlobals.adminID, senderIDs = floGlobals.subAdmins) {
|
||||||
|
showMessage('Loading the latest content')
|
||||||
|
await floCloudAPI.requestObjectData(ecommerce.master_configurations.SUBJECT, { receiverID, senderIDs });
|
||||||
|
await floCloudAPI.requestGeneralData(ecommerce.master_configurations.DATA_TYPE);
|
||||||
|
console.log(floGlobals.appObjects[ecommerce.master_configurations.SUBJECT]);
|
||||||
|
},
|
||||||
|
|
||||||
|
logout: function () {
|
||||||
|
if (confirm("Do you want to logout?")) {
|
||||||
|
floDapps.clearCredentials()
|
||||||
|
compactIDB.deleteDB().then((message) => {
|
||||||
|
delete ecommerce.master_configurations;
|
||||||
|
delete ecommerce.loggedInUser;
|
||||||
|
console.log(message)
|
||||||
|
onLoadStartUp()
|
||||||
|
alert('You have logged out successfully.')
|
||||||
|
}).catch((error) => {
|
||||||
|
console.log(error)
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ecommerce.users = {
|
ecommerce.users = {
|
||||||
current_user: function User(user_details='') {
|
current_user: function User(user_details='') {
|
||||||
|
|
||||||
if(typeof User.instance === 'object') return User.instance;
|
//if(typeof User.instance === 'object') return User.instance;
|
||||||
|
|
||||||
if(Object.keys(ecommerce.master_configurations.sellers_list)
|
if(Object.keys(ecommerce.master_configurations.sellers_list)
|
||||||
.includes(user_details.flo_id)) {
|
.includes(user_details.flo_id)) {
|
||||||
@ -10131,7 +10132,7 @@
|
|||||||
seller_details.certificate = ecommerce.master_configurations.sellers_list[myFloID].certificate;
|
seller_details.certificate = ecommerce.master_configurations.sellers_list[myFloID].certificate;
|
||||||
seller_details.location = ecommerce.master_configurations.sellers_list[myFloID].location;
|
seller_details.location = ecommerce.master_configurations.sellers_list[myFloID].location;
|
||||||
User.prototype.user_info = new ecommerce.users.user_types.sellers(seller_details);
|
User.prototype.user_info = new ecommerce.users.user_types.sellers(seller_details);
|
||||||
} else if(Object.keys(ecommerce.master_configurations.cashiers_list)
|
} else if(Object.keys(ecommerce.master_configurations.cashiers)
|
||||||
.includes(user_details.flo_id)) {
|
.includes(user_details.flo_id)) {
|
||||||
const cashier_details = {};
|
const cashier_details = {};
|
||||||
cashier_details.upi_id = ecommerce.master_configurations.cashiers[myFloID].upi_id;
|
cashier_details.upi_id = ecommerce.master_configurations.cashiers[myFloID].upi_id;
|
||||||
@ -10145,6 +10146,8 @@
|
|||||||
courier_details.approved_by = ecommerce.master_configurations.couriers_list[myFloID].approved_by;
|
courier_details.approved_by = ecommerce.master_configurations.couriers_list[myFloID].approved_by;
|
||||||
courier_details.certificate = ecommerce.master_configurations.couriers_list[myFloID].certificate;
|
courier_details.certificate = ecommerce.master_configurations.couriers_list[myFloID].certificate;
|
||||||
User.prototype.user_info = new ecommerce.users.user_types.couriers(user_details);
|
User.prototype.user_info = new ecommerce.users.user_types.couriers(user_details);
|
||||||
|
} else if(floGlobals.subAdmins.includes(user_details.flo_id)) {
|
||||||
|
User.prototype.user_info = new ecommerce.users.user_types.system_managers(user_details);
|
||||||
} else {
|
} else {
|
||||||
user_details.location = user_details.location || "";
|
user_details.location = user_details.location || "";
|
||||||
User.prototype.user_info = new ecommerce.users.user_types.buyers(user_details);
|
User.prototype.user_info = new ecommerce.users.user_types.buyers(user_details);
|
||||||
@ -10162,7 +10165,7 @@
|
|||||||
this[key] = obj;
|
this[key] = obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.buyer_id = myFloID;
|
this.flo_id = myFloID;
|
||||||
this.user_role = "BUYER";
|
this.user_role = "BUYER";
|
||||||
this.buy_list = [];
|
this.buy_list = [];
|
||||||
this.total_buying_price = 0;
|
this.total_buying_price = 0;
|
||||||
@ -10174,7 +10177,7 @@
|
|||||||
this[key] = obj;
|
this[key] = obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.seller_id = myFloID;
|
this.flo_id = myFloID;
|
||||||
this.user_role = "SELLER";
|
this.user_role = "SELLER";
|
||||||
},
|
},
|
||||||
cashiers: function Cashier(cashier_details={}) {
|
cashiers: function Cashier(cashier_details={}) {
|
||||||
@ -10184,7 +10187,7 @@
|
|||||||
this[key] = obj;
|
this[key] = obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.cashier_flo_id = myFloID;
|
this.flo_id = myFloID;
|
||||||
this.user_role = "CASHIER";
|
this.user_role = "CASHIER";
|
||||||
},
|
},
|
||||||
couriers: function Courier(courier_details={}) {
|
couriers: function Courier(courier_details={}) {
|
||||||
@ -10194,9 +10197,19 @@
|
|||||||
this[key] = obj;
|
this[key] = obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.courier_guy_flo_id = myFloID;
|
this.flo_id = myFloID;
|
||||||
this.user_role = "COURIER";
|
this.user_role = "COURIER";
|
||||||
},
|
},
|
||||||
|
system_managers: function(manager_details) {
|
||||||
|
for (const key in manager_details) {
|
||||||
|
if (manager_details.hasOwnProperty(key)) {
|
||||||
|
const obj = manager_details[key];
|
||||||
|
this[key] = obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.flo_id = myFloID;
|
||||||
|
this.user_role = "MANAGER";
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10209,18 +10222,33 @@
|
|||||||
for (const key in data) {
|
for (const key in data) {
|
||||||
if (data.hasOwnProperty(key)) {
|
if (data.hasOwnProperty(key)) {
|
||||||
const obj = data[key];
|
const obj = data[key];
|
||||||
|
if ((typeof obj === "string" && obj.length>0)
|
||||||
|
|| (typeof obj === "number" && obj>0)) {
|
||||||
this[key] = obj;
|
this[key] = obj;
|
||||||
|
} else {
|
||||||
|
showMessage("Invalid product property.");
|
||||||
|
throw new Error("Error: Product object creation failed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
this.product_flo_id = floCrypto.generateNewID().floID;
|
||||||
this.product_type = "PHYSICAL";
|
this.product_type = "PHYSICAL";
|
||||||
},
|
},
|
||||||
digital_products: function() {
|
digital_products: function() {
|
||||||
for (const key in data) {
|
for (const key in data) {
|
||||||
if (data.hasOwnProperty(key)) {
|
if (data.hasOwnProperty(key)) {
|
||||||
const obj = data[key];
|
const obj = data[key];
|
||||||
|
if ((typeof obj === "string" && obj.length>0)
|
||||||
|
|| (typeof obj === "number" && obj>0))
|
||||||
|
{
|
||||||
this[key] = obj;
|
this[key] = obj;
|
||||||
|
} else {
|
||||||
|
showMessage("Invalid product property.");
|
||||||
|
throw new Error("Error: Product object creation failed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
this.product_flo_id = floCrypto.generateNewID().floID;
|
||||||
this.product_type = "DIGITAL";
|
this.product_type = "DIGITAL";
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -10230,6 +10258,7 @@
|
|||||||
<script>
|
<script>
|
||||||
ecommerce.users.user_types.sellers.prototype = {
|
ecommerce.users.user_types.sellers.prototype = {
|
||||||
add_new_product: function(product_details) {
|
add_new_product: function(product_details) {
|
||||||
|
try {
|
||||||
let productClass = null;
|
let productClass = null;
|
||||||
if(product_details.product_type==="PHYSICAL") {
|
if(product_details.product_type==="PHYSICAL") {
|
||||||
productClass = "physical_products";
|
productClass = "physical_products";
|
||||||
@ -10238,11 +10267,40 @@
|
|||||||
} else return false;
|
} else return false;
|
||||||
// Generate a product object
|
// Generate a product object
|
||||||
const nayaProduct = new ecommerce.products[productClass](product_details);
|
const nayaProduct = new ecommerce.products[productClass](product_details);
|
||||||
nayaProduct.seller_flo_id = myFloID;
|
nayaProduct.seller_flo_id = ecommerce.loggedInUser.user_info.flo_id||myFloID;
|
||||||
nayaProduct.datetime = + new Date();
|
nayaProduct.datetime = + new Date();
|
||||||
nayaProduct.onSale = false;
|
nayaProduct.onSale = false;
|
||||||
compactIDB.addData('sellerProducts', nayaProduct);
|
|
||||||
return nayaProduct;
|
// Create a copy of above object but with only constant values
|
||||||
|
nayaProductConstants = {
|
||||||
|
product_flo_id: nayaProduct.product_flo_id,
|
||||||
|
product_type: nayaProduct.product_type,
|
||||||
|
seller_flo_id: nayaProduct.seller_flo_id,
|
||||||
|
product: nayaProduct.product,
|
||||||
|
product_category: nayaProduct.product_category,
|
||||||
|
selling_price: nayaProduct.selling_price,
|
||||||
|
delivery_from: nayaProduct.delivery_from
|
||||||
|
}
|
||||||
|
|
||||||
|
nayaProduct.seller_product_certificate={
|
||||||
|
signer_public_key: myPubKey,
|
||||||
|
signature: floCrypto.signData(JSON.stringify(nayaProductConstants), myPrivKey),
|
||||||
|
}
|
||||||
|
|
||||||
|
const ROOT_OBJECT = JSON.parse(JSON.stringify(floGlobals.appObjects[ecommerce.master_configurations.SUBJECT]));
|
||||||
|
|
||||||
|
ROOT_OBJECT[ecommerce.master_configurations.CITY]["Products"][nayaProduct.seller_flo_id]=nayaProduct;
|
||||||
|
|
||||||
|
//floCloudAPI.updateObjectData(floGlobals.appObjects[ecommerce.master_configurations.SUBJECT], ROOT_OBJECT, ecommerce.master_configurations.SUBJECT, { receiverID: floGlobals.adminID });
|
||||||
|
|
||||||
|
floCloudAPI.sendGeneralData(ROOT_OBJECT, ecommerce.master_configurations.DATA_TYPE, { receiverID: floGlobals.adminID, senderIDs: [myFloID] })
|
||||||
|
|
||||||
|
showMessage("Product added into the cloud successfully.", "SUCCESS");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
update_product_status: function(old_product_details, new_product_details) {
|
update_product_status: function(old_product_details, new_product_details) {
|
||||||
const object_values = Object.keys(obj1);
|
const object_values = Object.keys(obj1);
|
||||||
@ -10251,9 +10309,9 @@
|
|||||||
obj1[i] = product_details[i];
|
obj1[i] = product_details[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.list_product_for_sale();
|
this.list_products_to_sell();
|
||||||
},
|
},
|
||||||
list_product_for_sale: async function() {
|
list_products_to_sell: async function() {
|
||||||
const myProducts = await compactIDB.readAllData('sellerProducts');
|
const myProducts = await compactIDB.readAllData('sellerProducts');
|
||||||
const mySellingProducts = myProducts.filter(f=>(f.onSale===True && f.items_available>0));
|
const mySellingProducts = myProducts.filter(f=>(f.onSale===True && f.items_available>0));
|
||||||
console.table(mySellingProducts);
|
console.table(mySellingProducts);
|
||||||
@ -10318,8 +10376,12 @@
|
|||||||
shopping_details: this.buy_list,
|
shopping_details: this.buy_list,
|
||||||
total_shopping_price: this.total_buying_price,
|
total_shopping_price: this.total_buying_price,
|
||||||
date_of_purchase: + new Date(),
|
date_of_purchase: + new Date(),
|
||||||
location: 'Ranchi',
|
location: localStorage.getItem("FloECommerceUserAddress"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate Cashier UPI for payment
|
||||||
|
const cashier = randomNoRepeats(Object.keys(ecommerce.master_configurations.cashiers))();
|
||||||
|
final_buy_list.cashier = cashier;
|
||||||
final_buy_list.buyer_signature = floCrypto.signData(JSON.stringify(final_buy_list), myPrivKey);
|
final_buy_list.buyer_signature = floCrypto.signData(JSON.stringify(final_buy_list), myPrivKey);
|
||||||
|
|
||||||
// Send buy info to server
|
// Send buy info to server
|
||||||
@ -10330,34 +10392,24 @@
|
|||||||
|
|
||||||
this.reset_bucket_list();
|
this.reset_bucket_list();
|
||||||
|
|
||||||
// Generate Cashier UPI for payment
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
build_orders_object: function(cityname='') {
|
|
||||||
Orders = {};
|
|
||||||
Orders.city = {};
|
|
||||||
Orders.city[cityname] = {};
|
|
||||||
Orders.city[cityname].buy_orders = [];
|
|
||||||
Orders.city[cityname].sell_orders = [];
|
|
||||||
return Orders;
|
|
||||||
},
|
|
||||||
reset_bucket_list: function() {
|
reset_bucket_list: function() {
|
||||||
this.total_buying_price = 0;
|
this.total_buying_price = 0;
|
||||||
this.buy_list = [];
|
this.buy_list = [];
|
||||||
},
|
},
|
||||||
set_delivery_receiving_address: function() {
|
set_delivery_receiving_address: function() {
|
||||||
if (typeof(Storage) == "undefined") {
|
if (typeof(Storage) == "undefined") {
|
||||||
system_message('LocalStorage not supported.');
|
showMessage('LocalStorage not supported.');
|
||||||
throw new Error('LocalStorage not supported.');
|
throw new Error('LocalStorage not supported.');
|
||||||
}
|
}
|
||||||
let FloECommerceUserAddress = localStorage.getItem("FloECommerceUserAddress");
|
let FloECommerceUserAddress = localStorage.getItem("FloECommerceUserAddress");
|
||||||
if (FloECommerceUserAddress===null) {
|
if (FloECommerceUserAddress===null) {
|
||||||
FloECommerceUserAddress = prompt("Please enter your local address. We will fetch local services near you.");
|
FloECommerceUserAddress = prompt("Please enter your local address. We will fetch local services near you.");
|
||||||
if(typeof FloECommerceUserAddress!=="string" && FloECommerceUserAddress.length<1) {
|
if(typeof FloECommerceUserAddress!=="string" && FloECommerceUserAddress.length<1) {
|
||||||
system_message('Invalid Address. Please refresh to enter address again.');
|
showMessage('Invalid Address. Please refresh to enter address again.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
localStorage.setItem("FloECommerceUserAddress", FloECommerceUserAddress);
|
localStorage.setItem("FloECommerceUserAddress", FloECommerceUserAddress);
|
||||||
@ -10370,6 +10422,38 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- Managers functions -->
|
||||||
|
<script>
|
||||||
|
ecommerce.users.user_types.system_managers.prototype = {
|
||||||
|
create_new_city_ecommerce: function(cityname='') {
|
||||||
|
|
||||||
|
if(typeof cityname!=="string" || cityname.length<2) {
|
||||||
|
showMessage('Error: Please provide a city name.', 'error');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const flo_ecommerce = {};
|
||||||
|
flo_ecommerce[cityname] = {};
|
||||||
|
|
||||||
|
flo_ecommerce[cityname].Orders = {};
|
||||||
|
flo_ecommerce[cityname].Orders.buy_orders = {};
|
||||||
|
flo_ecommerce[cityname].Orders.sell_orders = {};
|
||||||
|
|
||||||
|
flo_ecommerce[cityname].Products = {};
|
||||||
|
|
||||||
|
flo_ecommerce[cityname].Messages = {};
|
||||||
|
flo_ecommerce[cityname].Messages["buyer_messages"] = {}
|
||||||
|
flo_ecommerce[cityname].Messages["seller_messages"] = {}
|
||||||
|
flo_ecommerce[cityname].Messages["cashier_messages"] = {}
|
||||||
|
flo_ecommerce[cityname].Messages["delivery_messages"] = {}
|
||||||
|
flo_ecommerce[cityname].Messages["manager_messages"] = {}
|
||||||
|
|
||||||
|
floCloudAPI.resetObjectData(flo_ecommerce, ecommerce.master_configurations.SUBJECT,
|
||||||
|
{ receiverID: floGlobals.adminID });
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user