Add a new route for username availability check

Though this query is using the same jamid service as the contact query,
they should handle the responses from jamid service differently.

Change-Id: I42da3c5fc05ffe721a33288a2c7276eb52a9c624
diff --git a/server/src/routers/nameserver-router.ts b/server/src/routers/nameserver-router.ts
index e0f27e9..037d279 100644
--- a/server/src/routers/nameserver-router.ts
+++ b/server/src/routers/nameserver-router.ts
@@ -47,6 +47,26 @@
   })
 );
 
+//Check if the username provided exists or not, if it doesn't exist, it is allowed for registration
+nameserverRouter.get(
+  '/username/availability/:username', //
+  asyncHandler(async (req, res) => {
+    //This is using the same jamid service as the route /username/:username, except the responses are handled different
+    const result = await jamid.lookupUsername(req.params.username, res.locals.accountId);
+    switch (result.state) {
+      case RegisteredNameFoundState.Found:
+        res.status(HttpStatusCode.Ok).send('taken');
+        break;
+      case RegisteredNameFoundState.InvalidResponse:
+        res.status(HttpStatusCode.BadRequest).send('Invalid username');
+        break;
+      default:
+        res.status(HttpStatusCode.Ok).send('available');
+        break;
+    }
+  })
+);
+
 nameserverRouter.get(
   '/address/:address',
   asyncHandler(async (req, res) => {