Browse Source

changes to msgTYpe when user is approved/rejected

push-params
Evan Feenstra 5 years ago
parent
commit
cb9e5a1d28
  1. 26
      api/controllers/chatTribes.ts
  2. 2
      api/controllers/index.ts
  3. 26
      dist/api/controllers/chatTribes.js
  4. 2
      dist/api/controllers/chatTribes.js.map
  5. 2
      dist/api/controllers/index.js
  6. 2
      dist/api/controllers/index.js.map

26
api/controllers/chatTribes.ts

@ -243,26 +243,33 @@ export async function editTribe(req, res) {
export async function approveOrRejectMember(req,res) {
console.log('=> approve or reject tribe member')
const chatId = parseInt(req.params['chatId'])
const msgId = parseInt(req.params['messageId'])
const contactId = parseInt(req.params['contactId'])
const status = req.params['status']
if(!chatId || !contactId || !(status==='approved'||status==='rejected')) {
const msg = await models.Message.findOne({ where: { id:msgId } })
if (!msg) return failure(res, 'no message')
const chatId = msg.chatId
const chat = await models.Chat.findOne({ where: { id:chatId } })
if (!chat) return failure(res, 'no chat')
if(!msgId || !contactId || !(status==='approved'||status==='rejected')) {
return failure(res, 'incorrect status')
}
const chat = await models.Chat.findOne({ where: { id:chatId } })
if (!chat) return
let memberStatus = constants.chat_statuses.rejected
let msgType = 'member_reject'
let msgType = constants.message_types.member_reject
if(status==='approved') {
memberStatus = constants.chat_statuses.approved
msgType = 'member_approve'
msgType = constants.message_types.member_approve
const contactIds = JSON.parse(chat.contactIds || '[]')
if(!contactIds.includes(contactId)) contactIds.push(contactId)
await chat.update({ contactIds: JSON.stringify(contactIds) })
}
await msg.update({type:msgType})
const member = await models.ChatMember.findOne({where:{contactId, chatId}})
if(!member) {
return failure(res, 'cant find chat member')
@ -278,11 +285,14 @@ export async function approveOrRejectMember(req,res) {
amount: 0,
sender: owner,
message: {},
type: constants.message_types[msgType],
type: msgType,
})
const theChat = await addPendingContactIdsToChat(chat)
success(res, jsonUtils.chatToJson(theChat))
success(res, {
chat: jsonUtils.chatToJson(theChat),
message: jsonUtils.messageToJson(msg, theChat)
})
}
export async function receiveMemberApprove(payload) {

2
api/controllers/index.ts

@ -41,7 +41,7 @@ export async function set(app) {
app.put('/chat/:id', chats.addGroupMembers)
app.put('/kick/:chat_id/:contact_id', chats.kickChatMember)
app.post('/tribe', chatTribes.joinTribe)
app.put('/member/:chatId/:contactId/:status', chatTribes.approveOrRejectMember)
app.put('/member/:contactId/:status/:messageId', chatTribes.approveOrRejectMember)
app.put('/group/:id', chatTribes.editTribe)
app.post('/upload', uploads.avatarUpload.single('file'), uploads.uploadFile)

26
dist/api/controllers/chatTribes.js

@ -235,25 +235,30 @@ exports.editTribe = editTribe;
function approveOrRejectMember(req, res) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> approve or reject tribe member');
const chatId = parseInt(req.params['chatId']);
const msgId = parseInt(req.params['messageId']);
const contactId = parseInt(req.params['contactId']);
const status = req.params['status'];
if (!chatId || !contactId || !(status === 'approved' || status === 'rejected')) {
return res_1.failure(res, 'incorrect status');
}
const msg = yield models_1.models.Message.findOne({ where: { id: msgId } });
if (!msg)
return res_1.failure(res, 'no message');
const chatId = msg.chatId;
const chat = yield models_1.models.Chat.findOne({ where: { id: chatId } });
if (!chat)
return;
return res_1.failure(res, 'no chat');
if (!msgId || !contactId || !(status === 'approved' || status === 'rejected')) {
return res_1.failure(res, 'incorrect status');
}
let memberStatus = constants.chat_statuses.rejected;
let msgType = 'member_reject';
let msgType = constants.message_types.member_reject;
if (status === 'approved') {
memberStatus = constants.chat_statuses.approved;
msgType = 'member_approve';
msgType = constants.message_types.member_approve;
const contactIds = JSON.parse(chat.contactIds || '[]');
if (!contactIds.includes(contactId))
contactIds.push(contactId);
yield chat.update({ contactIds: JSON.stringify(contactIds) });
}
yield msg.update({ type: msgType });
const member = yield models_1.models.ChatMember.findOne({ where: { contactId, chatId } });
if (!member) {
return res_1.failure(res, 'cant find chat member');
@ -267,10 +272,13 @@ function approveOrRejectMember(req, res) {
amount: 0,
sender: owner,
message: {},
type: constants.message_types[msgType],
type: msgType,
});
const theChat = yield addPendingContactIdsToChat(chat);
res_1.success(res, jsonUtils.chatToJson(theChat));
res_1.success(res, {
chat: jsonUtils.chatToJson(theChat),
message: jsonUtils.messageToJson(msg, theChat)
});
});
}
exports.approveOrRejectMember = approveOrRejectMember;

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

File diff suppressed because one or more lines are too long

2
dist/api/controllers/index.js

@ -48,7 +48,7 @@ function set(app) {
app.put('/chat/:id', chats.addGroupMembers);
app.put('/kick/:chat_id/:contact_id', chats.kickChatMember);
app.post('/tribe', chatTribes.joinTribe);
app.put('/member/:chatId/:contactId/:status', chatTribes.approveOrRejectMember);
app.put('/member/:contactId/:status/:messageId', chatTribes.approveOrRejectMember);
app.put('/group/:id', chatTribes.editTribe);
app.post('/upload', uploads.avatarUpload.single('file'), uploads.uploadFile);
app.post('/invites', invites.createInvite);

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

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