Browse Source

logz

push-params
Evan Feenstra 5 years ago
parent
commit
8ad13e52f7
  1. 7
      api/controllers/messages.ts
  2. 5
      dist/api/controllers/messages.js
  3. 2
      dist/api/controllers/messages.js.map

7
api/controllers/messages.ts

@ -91,18 +91,21 @@ export const getMessages = async (req, res) => {
export const getAllMessages = async (req, res) => {
const limit = (req.query.limit && parseInt(req.query.limit)) || 1000
const offset = (req.query.offset && parseInt(req.query.offset)) || 0
console.log(`=> getAllMessages, limit: ${limit}, offset: ${offset}`)
const messages = await models.Message.findAll({ order: [['chat_id', 'asc']], limit, offset })
console.log('=> got msgs',(messages&&messages.length))
const chatIds:number[] = []
messages.forEach((m) => {
if(!chatIds.includes(m.chatId)) {
chatIds.push(m.chatId)
}
})
console.log(`=> getAllMessages, limit: ${limit}, offset: ${offset}`)
let chats = chatIds.length > 0 ? await models.Chat.findAll({ where: {deleted:false, id: chatIds} }) : []
console.log('=> found all chats',(chats&&chats.length))
const chatsById = indexBy(chats, 'id')
console.log('=> indexed chats')
success(res, {
new_messages: messages.map(
message => jsonUtils.messageToJson(message, chatsById[parseInt(message.chatId)])

5
dist/api/controllers/messages.js

@ -87,16 +87,19 @@ exports.getMessages = (req, res) => __awaiter(void 0, void 0, void 0, function*
exports.getAllMessages = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const limit = (req.query.limit && parseInt(req.query.limit)) || 1000;
const offset = (req.query.offset && parseInt(req.query.offset)) || 0;
console.log(`=> getAllMessages, limit: ${limit}, offset: ${offset}`);
const messages = yield models_1.models.Message.findAll({ order: [['chat_id', 'asc']], limit, offset });
console.log('=> got msgs', (messages && messages.length));
const chatIds = [];
messages.forEach((m) => {
if (!chatIds.includes(m.chatId)) {
chatIds.push(m.chatId);
}
});
console.log(`=> getAllMessages, limit: ${limit}, offset: ${offset}`);
let chats = chatIds.length > 0 ? yield models_1.models.Chat.findAll({ where: { deleted: false, id: chatIds } }) : [];
console.log('=> found all chats', (chats && chats.length));
const chatsById = underscore_1.indexBy(chats, 'id');
console.log('=> indexed chats');
res_1.success(res, {
new_messages: messages.map(message => jsonUtils.messageToJson(message, chatsById[parseInt(message.chatId)])),
confirmed_messages: []

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

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