Create new interfaces for objects transmitted using the REST API
Changes:
- Create new IContact, IAccount, and IConversation interfaces in common/
- These interfaces represent the serialized versions of the models which are transferred
- The client models are classes which implement these interfaces
- Create new LookupResult interface for nameserver lookup results
- Create new IConversationMember interface for conversation members
- The client interface ConversationMember extends this interface to have a Contact field rather than IContact
- Create new ConversationInfos interface for conversation infos
- Create new ContactDetails interface for contact details (used by contacts routes)
- Move request and response body interfaces into common/
- Merge AccountConfig into AccountDetails interface
- Create interfaces for server-only objects:
- ConversationMemberInfos
- ConversationRequestMetadata
- Ensure interfaces in jami-signal-interfaces.ts do not contain fields with JamiSwig types
- Rename models/ filenames to camelCase as they are not components
- Rewrite client models to have proper TypeScript accessors and remove unused getters
- Rewrite how client models are initialized from the serialized interface using .fromInterface static methods
- Make client models implement the interfaces in common/ for consistency
- Remove unneeded _next parameter for Express.js route handlers
- Use Partial<T> for all Express.js request body types on server
- Type all Axios response body types with interfaces
GitLab: #92
Change-Id: I4b2c75ac632ec5d9bf12a874a5ba04467c76fa6d
diff --git a/server/src/routers/account-router.ts b/server/src/routers/account-router.ts
index 505d1d9..78963e7 100644
--- a/server/src/routers/account-router.ts
+++ b/server/src/routers/account-router.ts
@@ -15,9 +15,10 @@
* License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
-import { Router } from 'express';
+import { Request, Router } from 'express';
import asyncHandler from 'express-async-handler';
-import { AccountDetails, HttpStatusCode } from 'jami-web-common';
+import { ParamsDictionary } from 'express-serve-static-core';
+import { AccountDetails, HttpStatusCode, IAccount, IContact } from 'jami-web-common';
import { Container } from 'typedi';
import { Jamid } from '../jamid/jamid.js';
@@ -38,7 +39,7 @@
// Add usernames for default moderators
const defaultModeratorUris = jamid.getDefaultModeratorUris(accountId);
- const namedDefaultModerators = [];
+ const namedDefaultModerators: IContact[] = [];
for (const defaultModeratorUri of defaultModeratorUris) {
const { username } = await jamid.lookupAddress(defaultModeratorUri, accountId);
namedDefaultModerators.push({
@@ -47,17 +48,18 @@
});
}
- res.send({
+ const account: IAccount = {
id: accountId,
details: jamid.getAccountDetails(accountId),
volatileDetails: jamid.getVolatileAccountDetails(accountId),
defaultModerators: namedDefaultModerators,
devices: jamid.getDevices(accountId),
- });
+ };
+ res.send(account);
})
);
-accountRouter.patch('/', (req, res) => {
+accountRouter.patch('/', (req: Request<ParamsDictionary, string, Partial<AccountDetails>>, res) => {
const accountId = res.locals.accountId;
const currentAccountDetails = jamid.getAccountDetails(accountId);