Create conversations API routes
Changes:
- Create new conversationRouter with routes for conversations
- Add conversation-related methods to Jamid
- Use Message interface over Record<string, string>
- Add return type annotations for functions in Jamid
- Simplify returned value for account creation/registration
GitLab: #95
Change-Id: Ib0af8b60a92d08ddf4843f874c811e4ead870174
diff --git a/server/src/routers/auth-router.ts b/server/src/routers/auth-router.ts
index d0fc6f0..086f640 100644
--- a/server/src/routers/auth-router.ts
+++ b/server/src/routers/auth-router.ts
@@ -40,7 +40,7 @@
authRouter.post(
'/new-account',
- asyncHandler(async (req: Request<ParamsDictionary, any, Credentials>, res, _next) => {
+ asyncHandler(async (req: Request<ParamsDictionary, string, Credentials>, res, _next) => {
const { username, password } = req.body;
if (!username || !password) {
res.status(HttpStatusCode.BadRequest).send('Missing username or password');
@@ -55,10 +55,10 @@
// TODO: find a way to store the password directly in Jami
// Maybe by using the "password" field? But as I tested, it's not
// returned when getting user infos.
- const { accountId } = await jamid.addAccount(new Map());
+ const accountId = await jamid.addAccount(new Map());
// TODO: understand why the password arg in this call must be empty
- const { state } = await jamid.registerUsername(accountId, username, '');
+ const state = await jamid.registerUsername(accountId, username, '');
if (state !== 0) {
jamid.removeAccount(accountId);
if (state === 2) {
@@ -80,7 +80,7 @@
authRouter.post(
'/login',
- asyncHandler(async (req: Request<ParamsDictionary, any, Credentials>, res, _next) => {
+ asyncHandler(async (req: Request<ParamsDictionary, { accessToken: string } | string, Credentials>, res, _next) => {
const { username, password } = req.body;
if (!username || !password) {
res.status(HttpStatusCode.BadRequest).send('Missing username or password');
@@ -117,6 +117,6 @@
.setAudience('urn:example:audience')
.setExpirationTime('2h')
.sign(vault.privateKey);
- res.json({ accessToken: jwt });
+ res.send({ accessToken: jwt });
})
);