Browse Source

bots for tribe

push-params
Evan Feenstra 4 years ago
parent
commit
9530ddea8d
  1. 21
      api/controllers/actions.ts
  2. 1
      api/controllers/index.ts
  3. 23
      dist/api/controllers/actions.js
  4. 2
      dist/api/controllers/actions.js.map
  5. 1
      dist/api/controllers/index.js
  6. 2
      dist/api/controllers/index.js.map

21
api/controllers/actions.ts

@ -25,8 +25,29 @@ export const getBots = async (req, res) => {
}
}
export const getBotsForTribe = async (req, res) => {
const chat_id = req.params.chat_id
const chatId = parseInt(chat_id)
if(!chatId) return failure(res,'no chat id')
try {
const bots = await models.Bot.findAll({where:{chatId}})
success(res, {
bots: bots.map(b=> jsonUtils.botToJson(b))
})
} catch(e) {
failure(res,'no bots')
}
}
export const createBot = async (req, res) => {
const { chat_id, name, } = req.body
const chatId = parseInt(chat_id)
const chat = await models.Chat.findOne({where:{chatId}})
if(!chat) return failure(res,'no chat')
const owner = await models.Contact.findOne({where: {isOwner:true}})
const isTribeOwner = owner.publicKey===chat.ownerPubkey
if(!isTribeOwner) return failure(res, 'not tribe owner')
const newBot = {
id: crypto.randomBytes(8).toString('hex').toUpperCase(),

1
api/controllers/index.ts

@ -95,6 +95,7 @@ export async function set(app) {
app.post('/action', actions.processAction)
app.get('/bots', actions.getBots)
app.get('/bots/:chat_id',actions.getBotsForTribe)
app.post('/bot', actions.createBot)
app.delete('/bot/:id', actions.deleteBot)

23
dist/api/controllers/actions.js

@ -33,8 +33,31 @@ exports.getBots = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
res_1.failure(res, 'no bots');
}
});
exports.getBotsForTribe = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const chat_id = req.params.chat_id;
const chatId = parseInt(chat_id);
if (!chatId)
return res_1.failure(res, 'no chat id');
try {
const bots = yield models_1.models.Bot.findAll({ where: { chatId } });
res_1.success(res, {
bots: bots.map(b => jsonUtils.botToJson(b))
});
}
catch (e) {
res_1.failure(res, 'no bots');
}
});
exports.createBot = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const { chat_id, name, } = req.body;
const chatId = parseInt(chat_id);
const chat = yield models_1.models.Chat.findOne({ where: { chatId } });
if (!chat)
return res_1.failure(res, 'no chat');
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const isTribeOwner = owner.publicKey === chat.ownerPubkey;
if (!isTribeOwner)
return res_1.failure(res, 'not tribe owner');
const newBot = {
id: crypto.randomBytes(8).toString('hex').toUpperCase(),
chatId: chat_id,

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

File diff suppressed because one or more lines are too long

1
dist/api/controllers/index.js

@ -92,6 +92,7 @@ function set(app) {
app.get('/info', details.getNodeInfo);
app.post('/action', actions.processAction);
app.get('/bots', actions.getBots);
app.get('/bots/:chat_id', actions.getBotsForTribe);
app.post('/bot', actions.createBot);
app.delete('/bot/:id', actions.deleteBot);
app.get('/version', function (req, res) {

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

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