Browse Source

updateChat

bugfix/timeout-logging
Evan Feenstra 5 years ago
parent
commit
93c2e27283
  1. 22
      api/controllers/chats.ts
  2. 1
      api/controllers/index.ts
  3. 24
      dist/api/controllers/chats.js
  4. 2
      dist/api/controllers/chats.js.map
  5. 1
      dist/api/controllers/index.js
  6. 2
      dist/api/controllers/index.js.map

22
api/controllers/chats.ts

@ -13,6 +13,28 @@ import {replayChatHistory,createTribeChatParams} from './chatTribes'
const constants = require(path.join(__dirname,'../../config/constants.json'))
export async function updateChat(req, res){
console.log('=> updateChat')
const id = parseInt(req.params.id)
if(!id) {
return failure(res,'missing id')
}
const chat = await models.Chat.findOne({ where: { id }})
if(!chat) {
return failure(res,'chat not found')
}
const {name,photo_url} = req.body
const obj:{[k:string]:any} = {}
if(name) obj.name=name
if(photo_url) obj.photoUrl=photo_url
if(Object.keys(obj).length>0) {
await chat.update(obj)
}
success(res, jsonUtils.chatToJson(chat))
}
export async function kickChatMember(req, res){
const chatId = parseInt(req.params['chat_id'])
const contactId = parseInt(req.params['contact_id'])

1
api/controllers/index.ts

@ -35,6 +35,7 @@ export async function set(app) {
app.get('/chats', chats.getChats)
app.post('/group', chats.createGroupChat)
app.put('/chats/:id', chats.updateChat)
app.post('/chats/:chat_id/:mute_unmute', chats.mute)
app.delete('/chat/:id', chats.deleteChat)
app.put('/chat/:id', chats.addGroupMembers)

24
dist/api/controllers/chats.js

@ -22,6 +22,30 @@ const tribes = require("../utils/tribes");
const timers = require("../utils/timers");
const chatTribes_1 = require("./chatTribes");
const constants = require(path.join(__dirname, '../../config/constants.json'));
function updateChat(req, res) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> updateChat');
const id = parseInt(req.params.id);
if (!id) {
return res_1.failure(res, 'missing id');
}
const chat = yield models_1.models.Chat.findOne({ where: { id } });
if (!chat) {
return res_1.failure(res, 'chat not found');
}
const { name, photo_url } = req.body;
const obj = {};
if (name)
obj.name = name;
if (photo_url)
obj.photoUrl = photo_url;
if (Object.keys(obj).length > 0) {
yield chat.update(obj);
}
res_1.success(res, jsonUtils.chatToJson(chat));
});
}
exports.updateChat = updateChat;
function kickChatMember(req, res) {
return __awaiter(this, void 0, void 0, function* () {
const chatId = parseInt(req.params['chat_id']);

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

File diff suppressed because one or more lines are too long

1
dist/api/controllers/index.js

@ -42,6 +42,7 @@ function set(app) {
timers.reloadTimers();
app.get('/chats', chats.getChats);
app.post('/group', chats.createGroupChat);
app.put('/chats/:id', chats.updateChat);
app.post('/chats/:chat_id/:mute_unmute', chats.mute);
app.delete('/chat/:id', chats.deleteChat);
app.put('/chat/:id', chats.addGroupMembers);

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

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