Browse Source

getAllMsgs fix

push-params
Evan Feenstra 4 years ago
parent
commit
e104ccfe87
  1. 9
      api/controllers/messages.ts
  2. 9
      dist/api/controllers/messages.js
  3. 2
      dist/api/controllers/messages.js.map

9
api/controllers/messages.ts

@ -92,8 +92,13 @@ 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
const messages = await models.Message.findAll({ order: [['id', 'asc']], limit, offset })
const chatIds = messages.map(m => m.chatId)
const messages = await models.Message.findAll({ order: [['chat_id', 'asc']], limit, offset })
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} }) : []
const chatsById = indexBy(chats, 'id')

9
dist/api/controllers/messages.js

@ -87,8 +87,13 @@ 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;
const messages = yield models_1.models.Message.findAll({ order: [['id', 'asc']], limit, offset });
const chatIds = messages.map(m => m.chatId);
const messages = yield models_1.models.Message.findAll({ order: [['chat_id', 'asc']], limit, offset });
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 } }) : [];
const chatsById = underscore_1.indexBy(chats, 'id');

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

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