Browse Source

edit tribe params

push-params
Evan Feenstra 5 years ago
parent
commit
abd6135425
  1. 60
      api/controllers/chatTribes.ts
  2. 70
      dist/api/controllers/chatTribes.js
  3. 2
      dist/api/controllers/chatTribes.js.map

60
api/controllers/chatTribes.ts

@ -204,37 +204,41 @@ export async function editTribe(req, res) {
const owner = await models.Contact.findOne({ where: { isOwner: true } }) const owner = await models.Contact.findOne({ where: { isOwner: true } })
let okToUpdate = true let okToUpdate = true
try{ if (owner.publicKey===chat.ownerPubkey) {
await tribes.edit({ try{
uuid: chat.uuid, await tribes.edit({
name: name, uuid: chat.uuid,
host: chat.host, name: name,
price_per_message: price_per_message||0, host: chat.host,
price_to_join: price_to_join||0, price_per_message: price_per_message||0,
escrow_amount: escrow_amount||0, price_to_join: price_to_join||0,
escrow_millis: escrow_millis||0, escrow_amount: escrow_amount||0,
description, escrow_millis: escrow_millis||0,
tags, description,
img, tags,
owner_alias: owner.alias, img,
unlisted, owner_alias: owner.alias,
is_private: req.body.private unlisted,
}) is_private: req.body.private
} catch(e) { })
okToUpdate = false } catch(e) {
okToUpdate = false
}
} }
if(okToUpdate) { if(okToUpdate) {
await chat.update({ const obj:{[k:string]:any} = {}
photoUrl: img||'', if(img) obj.img=img
name: name, if(name) obj.name=name
pricePerMessage: price_per_message||0, if(price_per_message) obj.pricePerMessage=price_per_message
priceToJoin: price_to_join||0, if(price_to_join) obj.priceToJoin = price_to_join
escrowAmount: escrow_amount||0, if(escrow_amount) obj.escrowAmount = escrow_amount
escrowMillis: escrow_millis||0, if(escrow_millis) obj.escrowMillis = escrow_millis
unlisted: unlisted||false, if(unlisted) obj.unlisted = unlisted
private: req.body.private||false, if(req.body.private) obj.private = req.body.private
}) if(Object.keys(obj).length>0) {
await chat.update(obj)
}
success(res, jsonUtils.chatToJson(chat)) success(res, jsonUtils.chatToJson(chat))
} else { } else {
failure(res, 'failed to update tribe') failure(res, 'failed to update tribe')

70
dist/api/controllers/chatTribes.js

@ -193,37 +193,49 @@ function editTribe(req, res) {
} }
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } }); const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
let okToUpdate = true; let okToUpdate = true;
try { if (owner.publicKey === chat.ownerPubkey) {
yield tribes.edit({ try {
uuid: chat.uuid, yield tribes.edit({
name: name, uuid: chat.uuid,
host: chat.host, name: name,
price_per_message: price_per_message || 0, host: chat.host,
price_to_join: price_to_join || 0, price_per_message: price_per_message || 0,
escrow_amount: escrow_amount || 0, price_to_join: price_to_join || 0,
escrow_millis: escrow_millis || 0, escrow_amount: escrow_amount || 0,
description, escrow_millis: escrow_millis || 0,
tags, description,
img, tags,
owner_alias: owner.alias, img,
unlisted, owner_alias: owner.alias,
is_private: req.body.private unlisted,
}); is_private: req.body.private
} });
catch (e) { }
okToUpdate = false; catch (e) {
okToUpdate = false;
}
} }
if (okToUpdate) { if (okToUpdate) {
yield chat.update({ const obj = {};
photoUrl: img || '', if (img)
name: name, obj.img = img;
pricePerMessage: price_per_message || 0, if (name)
priceToJoin: price_to_join || 0, obj.name = name;
escrowAmount: escrow_amount || 0, if (price_per_message)
escrowMillis: escrow_millis || 0, obj.pricePerMessage = price_per_message;
unlisted: unlisted || false, if (price_to_join)
private: req.body.private || false, obj.priceToJoin = price_to_join;
}); if (escrow_amount)
obj.escrowAmount = escrow_amount;
if (escrow_millis)
obj.escrowMillis = escrow_millis;
if (unlisted)
obj.unlisted = unlisted;
if (req.body.private)
obj.private = req.body.private;
if (Object.keys(obj).length > 0) {
yield chat.update(obj);
}
res_1.success(res, jsonUtils.chatToJson(chat)); res_1.success(res, jsonUtils.chatToJson(chat));
} }
else { else {

2
dist/api/controllers/chatTribes.js.map

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save