Browse Source

getAllMessages with pagination

feature/dockerfile-arm
Evan Feenstra 5 years ago
parent
commit
119293ffa9
  1. 1
      api/controllers/index.ts
  2. 10
      api/controllers/messages.ts
  3. 1
      dist/api/controllers/index.js
  4. 2
      dist/api/controllers/index.js.map
  5. 7
      dist/api/controllers/messages.js
  6. 2
      dist/api/controllers/messages.js.map

1
api/controllers/index.ts

@ -78,6 +78,7 @@ async function set(app) {
app.post('/contacts', controllers.contacts.createContact)
app.delete('/contacts/:id', controllers.contacts.deleteContact)
app.get('/allmessages', controllers.messages.getAllMessages)
app.get('/messages', controllers.messages.getMessages)
app.delete('/message/:id', controllers.messages.deleteMessage)
app.post('/messages', controllers.messages.sendMessage)

10
api/controllers/messages.ts

@ -69,9 +69,12 @@ const getMessages = async (req, res) => {
}
const getAllMessages = async (req, res) => {
const messages = await models.Message.findAll({ order: [['id', 'asc']] })
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)
console.log('=> getAllMessages, chatIds',chatIds)
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')
@ -210,5 +213,6 @@ export {
receiveMessage,
clearMessages,
readMessages,
deleteMessage
deleteMessage,
getAllMessages,
}

1
dist/api/controllers/index.js

@ -83,6 +83,7 @@ function set(app) {
app.post('/contacts/:id/keys', controllers.contacts.exchangeKeys);
app.post('/contacts', controllers.contacts.createContact);
app.delete('/contacts/:id', controllers.contacts.deleteContact);
app.get('/allmessages', controllers.messages.getAllMessages);
app.get('/messages', controllers.messages.getMessages);
app.delete('/message/:id', controllers.messages.deleteMessage);
app.post('/messages', controllers.messages.sendMessage);

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

File diff suppressed because one or more lines are too long

7
dist/api/controllers/messages.js

@ -68,9 +68,11 @@ const getMessages = (req, res) => __awaiter(void 0, void 0, void 0, function* ()
});
exports.getMessages = getMessages;
const getAllMessages = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const messages = yield models_1.models.Message.findAll({ order: [['id', 'asc']] });
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);
console.log('=> getAllMessages, chatIds', chatIds);
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');
res_1.success(res, {
@ -78,6 +80,7 @@ const getAllMessages = (req, res) => __awaiter(void 0, void 0, void 0, function*
confirmed_messages: []
});
});
exports.getAllMessages = getAllMessages;
function deleteMessage(req, res) {
return __awaiter(this, void 0, void 0, function* () {
const id = req.params.id;

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

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