feat: GET /api/v3/chats

This commit is contained in:
Julian Lam
2021-12-13 11:47:48 -05:00
parent 02e878be72
commit 94bead71fe
3 changed files with 19 additions and 12 deletions

View File

@@ -1,14 +1,20 @@
/* eslint-disable */
'use strict';
const api = require('../../api');
const messaging = require('../../messaging');
const helpers = require('../helpers');
const Chats = module.exports;
Chats.list = async (req, res) => {
// ...
const page = (isFinite(req.query.page) && parseInt(req.query.page, 10)) || 1;
const perPage = (isFinite(req.query.perPage) && parseInt(req.query.perPage, 10)) || 20;
const start = Math.max(0, page - 1) * perPage;
const stop = start + perPage;
const { rooms } = await messaging.getRecentChats(req.uid, req.uid, start, stop);
helpers.formatApiResponse(200, res, { rooms });
};
Chats.create = async (req, res) => {
@@ -39,7 +45,7 @@ Chats.kick = async (req, res) => {
// ...
};
Chats.message = {};
Chats.messages = {};
Chats.messages.edit = async (req, res) => {
// ...
};