Repository: spaship/spaship
Pull request #1689 (2022-05-06 09:25:17)

feat(api) : changes in api (develop to master)
<!--
Follow the steps to create the PR:

Subject: "feat/fix/docs(#issue_id): <PR Subject>"
Assignees: "Developers"
Projects: ""
-->

## Closes / Fixes / Resolves

<!-- Comman separated list of GitHub Issue ID(s) -->

## Explain the feature/fix

<!-- Provide a clear explaination of the feature/fix implemented -->

## Does this PR introduce a breaking change

<!-- Yes/No -->

<!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications here. -->

## Screenshot(s)

<!-- If applicable, add screenshots to help explain your problem. -->

<details>
<summary>View Screenshots</summary>

<!-- Add your screenshot(s) below this line -->

</details>

### Ready-for-merge Checklist

- [ ] Expected files: all files in this pull request are related to one feature request or issue (no stragglers)?
- [ ] Does the change have appropriate unit tests?
- [ ] Did you update or add any necessary documentation (README.md, WHY.md, etc.)?
- [ ] Was this feature demo'd and the design review approved?



Patch:
diff --git a/packages/api/controllers/application.js b/packages/api/controllers/application.js
index 3a051c04..ff9562aa 100644
--- a/packages/api/controllers/application.js
+++ b/packages/api/controllers/application.js
@@ -12,12 +12,13 @@ const { uuid } = require("uuidv4");
 const jwt = require("jsonwebtoken");
 const alias = require("../models/alias");
 const _ = require("lodash");
-
+const APIKey = require("../models/apiKey");
 const axios = require("axios");
 const FormData = require("form-data");
 const fs = require("fs");
 const path = require("path");
 const config = require("../config");
+const { hash } = require("../utils/cryptoUtil");
 
 module.exports.list = async (req, res, next) => {
   const list = await FileService.getAll();
@@ -173,11 +174,31 @@ module.exports.delete = async (req, res, next) => {
 };
 
 module.exports.validate = async (req, res, next) => {
-  const expiration = config.get("token:expiration");
+  const expiration = req.body?.expiresIn || config.get("token:expiration");
   const secret = config.get("token:secret");
   const token = jwt.sign({ createdAt: new Date(), expiresIn: expiration }, secret, {
     expiresIn: expiration,
   });
+  let result = null;
+
+  if (req.body?.label == "spaship-cli-token") {
+    const label = req.body?.label;
+    const expiredDate = formatDate(new Date(), 1, 2);
+    const key = token;
+    const userId = uuid() + key.substring(0, 4);
+    const shortKey = hash(userId);
+    const hashKey = token;
+    const data = {
+      label,
+      shortKey,
+      hashKey,
+      userId,
+      expiredDate,
+    };
+    result = await APIKey.create(data);
+    return res.status(200).json({ message: "Validation is successful.", token: result?.userId });
+  }
+
   res.status(200).json({ message: "Validation is successful.", token: token });
 };
 
@@ -232,3 +253,15 @@ function getWebPropertyName(req) {
 
   return req?.body?.webPropertyName || false;
 }
+
+function formatDate(date, month, days) {
+  var d = new Date(date),
+    month = "" + (d.getMonth() + month),
+    day = "" + (d.getDate() + days),
+    year = d.getFullYear();
+
+  if (month.length < 2) month = "0" + month;
+  if (day.length < 2) day = "0" + day;
+
+  return [year, month, day].join("-");
+}
diff --git a/packages/api/controllers/operatorServices/consumeEvent.js b/packages/api/controllers/operatorServices/consumeEvent.js
index cfeb61e4..60137bca 100644
--- a/packages/api/controllers/operatorServices/consumeEvent.js
+++ b/packages/api/controllers/operatorServices/consumeEvent.js
@@ -14,11 +14,13 @@ source.onmessage = function (eventRequest) {
   const eventBody = new event({
     id: uuid(),
     eventId: response?.uuid,
-    propertyName: response?.websiteName,
-    spaName: response?.spaName || 'NA',
+    propertyName: response?.websiteName || "NA",
+    spaName: response?.spaName || "NA",
     version: 1,
-    envs: response.environmentName,
+    env: response.environmentName,
     branch: "main",
+    path: "",
+    url: "",
     code: getCode(response.state),
     failure: false,
     isActive: true,
@@ -33,7 +35,7 @@ source.onmessage = function (eventRequest) {
 function getCode(state) {
   if (state == "mapping file loaded into memory") return "WEBSITE_CREATE_STARTED";
   if (state == "spa deployment ops performed") return "WEBSITE_CREATE";
-  return undefined;
+  return "";
 }
 
 async function createEventRequest(response) {
@@ -52,11 +54,11 @@ async function createEventTimeTraceRequest(response) {
     id: uuid(),
     traceId: response.uuid,
     propertyName: response.websiteName,
-    envs: response.environmentName,
+    env: response.environmentName,
     spaName: response?.spaName,
     initialCode: "WEBSITE_CREATE_STARTED",
     finalCode: "WEBSITE_CREATE",
-    failure: true,
+    failure: false,
     createdAt: eventRequest.createdAt,
     completedAt: currentTime,
     consumedTime: consumedTime,
diff --git a/packages/api/controllers/operatorServices/saveAlias.js b/packages/api/controllers/operatorServices/saveAlias.js
index 360a48af..3079753a 100644
--- a/packages/api/controllers/operatorServices/saveAlias.js
+++ b/packages/api/controllers/operatorServices/saveAlias.js
@@ -1,18 +1,54 @@
 const alias = require("../../models/alias");
 const { uuid } = require("uuidv4");
+const ValidationError = require("../../utils/errors/ValidationError");
 
-module.exports = async function saveAlias(req, res) {
+module.exports = async function saveAlias(req, res, next) {
   console.log(req.body);
-  if (req.body?.id) {
-    const updatedResponse = await updateAlias(req);
-    res.send(updatedResponse);
+  const request = req.body;
+  if (!validateProperty(request, next)) return;
+  if (request?.id) {
+    const updatedResponse = await updateAlias(request);
+    return res.send(updatedResponse);
+  }
+  if (!request.hasOwnProperty("propertyName") || !request.hasOwnProperty("propertyTitle")) {
+    return next(new ValidationError("Please provide PropertyName and PropertyTitle"));
+  }
+  const result = await alias.findOne({ propertyName: getPropertyName(request), env: getEnv(request) });
+  if (result) {
+    return next(new ValidationError("Propertyname & Env exists."));
   }
   let id = await getGeneratedAliasId();
-  let aliasRequest = await createAliasRequest(id, req);
+  let aliasRequest = await createAliasRequest(id, request);
   const createdResponse = await createEvent(aliasRequest);
   res.send(createdResponse);
 };
 
+function validateProperty(request, next) {
+  const formatPropertyName = /[ `!@#$%^&*()_+\=\[\]{};':"\\|,.<>\/?~]/;
+  const formatEnv = /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
+  const formatUrl = /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,<>\/?~]/;
+  if (request?.propertyName?.trim().match(formatPropertyName)) {
+    next(new ValidationError("Invalid PropertyName"));
+    return false;
+  }
+  if (request?.env?.trim().match(formatEnv)) {
+    next(new ValidationError("Invalid Env"));
+    return false;
+  }
+  if (request?.url?.trim().match(formatUrl)) {
+    next(new ValidationError("Invalid Url"));
+    return false;
+  }
+  if (request.hasOwnProperty("type")) {
+    const type = request?.type?.trim()?.toLowerCase();
+    if (type != "operator" && type != "baremetal") {
+      next(new ValidationError("Property Type must be operator or baremetal"));
+      return false;
+    }
+  }
+  return true;
+}
+
 async function createEvent(aliasRequest) {
   try {
     const saveResponse = await aliasRequest.save();
@@ -26,20 +62,26 @@ async function getGeneratedAliasId() {
   return uuid();
 }
 
-async function createAliasRequest(id, req) {
+async function createAliasRequest(id, request) {
   const currentTime = getCurrentTime();
   return new alias({
     id: id,
-    property: getPropertyName(req),
-    env: getEnv(req),
-    namespace: getNameSpace(req),
-    type: getType(req),
+    propertyName: getPropertyName(request),
+    propertyTitle: getPropertyTitle(request),
+    env: getEnv(request),
+    url: getUrl(request),
+    namespace: getNameSpace(request),
+    type: getType(request),
+    createdBy: getCreatedBy(request),
+    isActive: true,
     createdAt: currentTime,
+    updatedAt: currentTime,
   });
 }
 
-async function updateAlias(req) {
-  const updateResponse = await alias.findOneAndUpdate({ id: req.body?.id }, updateAliasRequest(req), (error, data) => {
+async function updateAlias(request) {
+  const updateData = { ...request, updatedAt: getCurrentTime() };
+  const updateResponse = await alias.findOneAndUpdate({ id: request?.id }, updateData, (error, data) => {
     if (error) {
       console.log("error");
     }
@@ -47,37 +89,34 @@ async function updateAlias(req) {
   return updateResponse;
 }
 
-async function updateAliasRequest(req) {
-  const updateRequest = {
-    property: getPropertyName(req),
-    env: getEnv(req),
-    namespace: getNameSpace(req),
-    type: getType(req),
-    createdAt: getCurrentTime(),
-  };
-  return JSON.parse(JSON.stringify(updateRequest));
-}
-
 function getCurrentTime() {
   return new Date();
 }
 
-function getPropertyName(req) {
-  return req.body?.property;
+function getPropertyName(request) {
+  return request.propertyName.trim().toLowerCase();
+}
+
+function getPropertyTitle(request) {
+  return request?.propertyTitle?.trim() || "";
+}
+
+function getCreatedBy(request) {
+  return request?.createdBy?.trim()?.toLowerCase() || "";
 }
 
-function getName(req) {
-  return req.body?.name || "";
+function getEnv(request) {
+  return request.env.trim().toLowerCase();
 }
 
-function getEnv(req) {
-  return req.body?.env;
+function getNameSpace(request) {
+  return request?.namespace?.trim()?.toLowerCase() || "";
 }
 
-function getNameSpace(req) {
-  return req.body?.namespace;
+function getType(request) {
+  return request?.type?.trim()?.toLowerCase() || "operator";
 }
 
-function getType(req) {
-  return req.body?.type;
+function getUrl(request) {
+  return request?.url?.trim()?.toLowerCase() || "";
 }
diff --git a/packages/api/controllers/operatorServices/saveEvent.js b/packages/api/controllers/operatorServices/saveEvent.js
index 47f18948..b9cd2c99 100644
--- a/packages/api/controllers/operatorServices/saveEvent.js
+++ b/packages/api/controllers/operatorServices/saveEvent.js
@@ -34,7 +34,7 @@ async function createEventRequest(eventId, req) {
         propertyName: getPropertyName(req) ,
         spaName: getSPAName(req) ,
         version: getVersion(req) ,
-        envs: getEnvs(),
+        env: getEnvs(),
         branch: getBranch(),
         code: getCode(),
         failure: getFailure(req) ,
@@ -52,7 +52,7 @@ async function createEventRequest(eventId, req) {
     }
 
     function getEnvs() {
-        return req.body?.envs;
+        return req.body?.env;
     }
 }
 
@@ -73,7 +73,7 @@ async function updateEventRequest(req) {
         propertyName: getPropertyName(req) ,
         spaName: getSPAName(req) ,
         version: getVersion(req) ,
-        envs: getEnvs(),
+        env: getEnvs(),
         branch: getBranch(),
         code: getCode(),
         failure: getFailure(req) ,
diff --git a/packages/api/controllers/scripts/aliasDataDump.js b/packages/api/controllers/scripts/aliasDataDump.js
new file mode 100644
index 00000000..77642d01
--- /dev/null
+++ b/packages/api/controllers/scripts/aliasDataDump.js
@@ -0,0 +1,43 @@
+const alias = require("../../models/alias");
+const mongoose = require("mongoose");
+const uuidv4 = require("uuid").v4;
+
+const aliasDataDump = async (req, res) => {
+  res.status(200).json(await aliasDataDumpService(getDocument(req)));
+};
+
+const aliasDataDumpService = async (docs) => {
+  try {
+    const bulk = await alias.collection.initializeUnorderedBulkOp();
+    const currentDate = new Date();
+    createBulkData(docs, currentDate, bulk);
+    bulk.execute();
+    console.log(docs);
+    return { Success: "All data successfully updated", "Records Number": getDocumentCounts(docs) };
+  } catch (e) {
+    console.log(e);
+  }
+};
+
+function getDocumentCounts(docs) {
+  return docs?.length || 0;
+}
+
+function getDocument(req) {
+  return req?.body || [];
+}
+
+function createBulkData(docs, currentDate, bulk) {
+  for (i = 0; i < getDocumentCounts(docs); i += 1) {
+    docs[i]._id = null;
+    if (docs[i].createdAt || docs[i].updatedAt) {
+      docs[i].id = uuidv4();
+      docs[i].createdAt = currentDate;
+      docs[i].updatedAt = currentDate;
+      console.log(docs[i]);
+      bulk.insert(docs[i]);
+    }
+  }
+}
+
+module.exports = { aliasDataDump, aliasDataDumpService };
diff --git a/packages/api/controllers/services/analyticsServiceAll.js b/packages/api/controllers/services/analyticsServiceAll.js
index c35ed6d7..52e64b7a 100644
--- a/packages/api/controllers/services/analyticsServiceAll.js
+++ b/packages/api/controllers/services/analyticsServiceAll.js
@@ -12,6 +12,7 @@ const analyticsServiceAll = async (req, res) => {
 };
 
 const propertyFilteration = async (request) => {
+  console.log(request);
   if (request?.count) {
     if (request?.count?.all == true) {
       return await getCounts.getCountService(
@@ -79,15 +80,45 @@ const propertyFilteration = async (request) => {
           code: "WEBSITE_CREATE",
         },
         {
-          envs: "$envs",
+          env: "$env",
         },
         {
           _id: 0,
-          envs: "$_id.envs",
+          env: "$_id.env",
           count: "$count",
         }
       );
     } else if (request?.chart.all == true) {
+      return await getCountByEnvWeeklyChart.getCountByEnvWeeklyChartService(
+        {
+          code: "WEBSITE_CREATE",
+        },
+        {
+          env: "$env",
+        },
+        {
+          _id: 0,
+          spaName: "$_id.spaName",
+          env: "$_id.env",
+          count: "$count",
+        }
+      );
+    } else if (request?.activities.all == true) {
+      return await getCountByEnvWeeklyChart.getCountByEnvWeeklyChartService(
+        {
+          code: "WEBSITE_CREATE",
+        },
+        {
+          env: "$env",
+        },
+        {
+          _id: 0,
+          spaName: "$_id.spaName",
+          env: "$_id.env",
+          count: "$count",
+        }
+      );
+    } else if (request?.activities.all == true) {
       return await getCountByEnvWeeklyChart.getCountByEnvWeeklyChartService(
         {
           code: "WEBSITE_CREATE",
diff --git a/packages/api/controllers/services/analyticsServiceFilter.js b/packages/api/controllers/services/analyticsServiceFilter.js
index c1dd86a1..b307d4df 100644
--- a/packages/api/controllers/services/analyticsServiceFilter.js
+++ b/packages/api/controllers/services/analyticsServiceFilter.js
@@ -14,6 +14,7 @@ const analyticsServiceFilter = async (req, res) => {
 };
 
 const analyticsOperations = async (request) => {
+  console.log(request);
   if (request?.count) {
     if (getPropertyName(request?.count) && getSpaName(request?.count)) {
       return await getCounts.getCountService(
@@ -26,14 +27,14 @@ const analyticsOperations = async (request) => {
           propertyName: "$propertyName",
           spaName: "$spaName",
           code: "$code",
-          envs: "$envs",
+          env: "$env",
         },
         {
           _id: 0,
           propertyName: "$_id.propertyName",
           spaName: "$_id.spaName",
           code: "$_id.code",
-          env: "$_id.envs",
+          env: "$_id.env",
           count: "$count",
         }
       );
@@ -59,14 +60,23 @@ const analyticsOperations = async (request) => {
     }
   } else if (request?.activities) {
     if (getPropertyName(request?.activities) && getSpaName(request?.activities)) {
-      return await getLatestActivities.getLatestActivitiesService({
-        propertyName: getPropertyName(request?.activities),
-        spaName: getSpaName(request?.activities),
-      });
+      return await getLatestActivities.getLatestActivitiesService(
+        {
+          propertyName: getPropertyName(request?.activities),
+          spaName: getSpaName(request?.activities),
+        },
+        { limit: getLimit(request?.activities) },
+        { skip: getSkip(request?.activities) }
+      );
     } else if (request?.activities.propertyName) {
-      return await getLatestActivities.getLatestActivitiesService({
-        propertyName: getPropertyName(request?.activities),
-      });
+      return await getLatestActivities.getLatestActivitiesService(
+        {
+          code: "WEBSITE_CREATE",
+          propertyName: getPropertyName(request?.activities),
+        },
+        { limit: getLimit(request?.activities) },
+        { skip: getSkip(request?.activities) }
+      );
     }
   } else if (request?.chart) {
     if (getMonth(request) == true && getPropertyName(request?.chart) && getSpaName(request?.chart)) {
@@ -78,12 +88,12 @@ const analyticsOperations = async (request) => {
         },
         {
           spaName: getSpaName(request?.chart),
-          envs: "$envs",
+          env: "$env",
         },
         {
           _id: 0,
           spaName: "$_id.spaName",
-          envs: "$_id.envs",
+          env: "$_id.env",
           count: "$count",
         }
       );
@@ -96,12 +106,12 @@ const analyticsOperations = async (request) => {
         },
         {
           propertyName: getPropertyName(request?.chart),
-          envs: "$envs",
+          env: "$env",
         },
         {
           _id: 0,
           propertyName: "$_id.propertyName",
-          envs: "$_id.envs",
+          env: "$_id.env",
           count: "$count",
         }
       );
@@ -115,12 +125,12 @@ const analyticsOperations = async (request) => {
         },
         {
           spaName: getSpaName(request?.spaName),
-          envs: "$envs",
+          env: "$env",
         },
         {
           _id: 0,
           spaName: "$_id.spaName",
-          envs: "$_id.envs",
+          env: "$_id.env",
           count: "$count",
         }
       );
@@ -131,12 +141,12 @@ const analyticsOperations = async (request) => {
         },
         {
           propertyName: getPropertyName(request?.chart),
-          envs: "$envs",
+          env: "$env",
         },
         {
           _id: 0,
           propertyName: "$_id.propertyName",
-          envs: "$_id.envs",
+          env: "$_id.env",
           count: "$count",
         }
       );
@@ -163,4 +173,12 @@ function getSpaName(request) {
 
 function getPropertyName(request) {
   return request?.propertyName;
-}
\ No newline at end of file
+}
+
+function getLimit(request) {
+  return parseInt(request?.limit) || 15;
+}
+
+function getSkip(request) {
+  return parseInt(request?.skip) || 0;
+}
diff --git a/packages/api/controllers/webProperties/getAliasList.js b/packages/api/controllers/webProperties/getAliasList.js
index 673b5419..3ad6291c 100644
--- a/packages/api/controllers/webProperties/getAliasList.js
+++ b/packages/api/controllers/webProperties/getAliasList.js
@@ -1,11 +1,16 @@
 const alias = require("../../models/alias");
 
-module.exports = async function getAliasList(req,res, next) {
+module.exports = async function getAliasList(req, res, next) {
   try {
+    const { name } = req?.params;
+    if (name) {
+      const response = await alias.find({ propertyName: name });
+      return res.status(200).json(response);
+    }
     const response = await alias.find();
     if (response.length === 0) return res.status(200).json({ message: "No data avaliable." });
-    res.status(200).json(response);
+    return res.status(200).json(response);
   } catch (e) {
     next(err);
   }
-}
\ No newline at end of file
+};
diff --git a/packages/api/controllers/webProperties/saveWebProperty.js b/packages/api/controllers/webProperties/saveWebProperty.js
index 7c79d811..bc84cd2a 100644
--- a/packages/api/controllers/webProperties/saveWebProperty.js
+++ b/packages/api/controllers/webProperties/saveWebProperty.js
@@ -66,7 +66,7 @@ function getSpas(req, reqBody) {
         repositoryLink: each?.repositoryLink,
         spaName: each?.webPropertyName,
         contextPath: each?.contextPath,
-        envs: each?.envs,
+        env: each?.env,
         ownerEmail : reqBody.body?.ownerEmail,
         ownerName: reqBody.body?.ownerName
     }));
diff --git a/packages/api/controllers/webPropertyServices/getCountByEnvWeeklyChart.js b/packages/api/controllers/webPropertyServices/getCountByEnvWeeklyChart.js
index 4ffc9ac8..047eab4a 100644
--- a/packages/api/controllers/webPropertyServices/getCountByEnvWeeklyChart.js
+++ b/packages/api/controllers/webPropertyServices/getCountByEnvWeeklyChart.js
@@ -46,10 +46,10 @@ async function fetchResponse(dateFrame, matchRequest, groupRequest, projectReque
   const mappedResponse = {};
   for (item of response) {
     for (obj of item) {
-      if (mappedResponse[obj.envs]) {
-        mappedResponse[obj.envs].push(obj);
+      if (mappedResponse[obj.env]) {
+        mappedResponse[obj.env].push(obj);
       } else {
-        mappedResponse[obj.envs] = [obj];
+        mappedResponse[obj.env] = [obj];
       }
     }
   }
@@ -81,12 +81,12 @@ async function getWeeklyReport(startDate, endDate, matchRequest, groupRequest, p
       $project: {
         _id: 0,
         spaName: "$_id.spaName",
-        envs: "$_id.envs",
+        env: "$_id.env",
         count: "$count",
       },
     },
     {
-      $sort: { envs: 1 },
+      $sort: { env: 1 },
     },
   ]);
 }
diff --git a/packages/api/controllers/webPropertyServices/utils/getSearchResultForSPA.js b/packages/api/controllers/webPropertyServices/utils/getSearchResultForSPA.js
index 47d03298..1f3905a9 100644
--- a/packages/api/controllers/webPropertyServices/utils/getSearchResultForSPA.js
+++ b/packages/api/controllers/webPropertyServices/utils/getSearchResultForSPA.js
@@ -1,8 +1,10 @@
-const chart = require("../../../models/event");
+const event = require("../../../models/event");
 
 const getSearchResultForSPA = async (req, res, next) => {
   try {
-    res.status(200).json(await getSearchResultForSPAService(req.sanitize(req.params.searchQuery)));
+    if (req.params.searchQuery)
+      res.status(200).json(await getSearchResultForSPAService(req.sanitize(req.params.searchQuery)));
+    else res.status(200).json(await event.find());
   } catch (err) {
     next(err);
   }
@@ -10,7 +12,7 @@ const getSearchResultForSPA = async (req, res, next) => {
 
 const getSearchResultForSPAService = async (searchQuery) => {
   const response = await fetchSearchResultForSPA(searchQuery);
-  if(response.length === 0) return { message : "Searched SPA is not avaliable."}
+  if (response.length === 0) return { message: "Searched SPA is not avaliable." };
   bindResponse(response);
   return response;
 };
@@ -23,7 +25,7 @@ function bindResponse(response) {
 }
 
 async function fetchSearchResultForSPA(searchQuery) {
-  return await chart.aggregate([
+  return await event.aggregate([
     {
       $group: {
         _id: {
diff --git a/packages/api/controllers/webPropertyServices/utils/getTimeFrameForPropertyChart.js b/packages/api/controllers/webPropertyServices/utils/getTimeFrameForPropertyChart.js
index e12573a9..218aaf17 100644
--- a/packages/api/controllers/webPropertyServices/utils/getTimeFrameForPropertyChart.js
+++ b/packages/api/controllers/webPropertyServices/utils/getTimeFrameForPropertyChart.js
@@ -46,11 +46,11 @@ async function fetchResponse(dateFrame, propertyName) {
   const mappedResponse = {};
   for(item of response){
     for(obj of item){
-      if(mappedResponse[obj.envs]){
-        mappedResponse[obj.envs].push(obj);
+      if(mappedResponse[obj.env]){
+        mappedResponse[obj.env].push(obj);
       }
       else{
-        mappedResponse[obj.envs] = [obj];
+        mappedResponse[obj.env] = [obj];
       }
     }
   }
@@ -77,7 +77,7 @@ async function getWeeklyReport(startDate, endDate, propertyName) {
       $group: {
         _id: {
           propertyName: "$propertyName",
-          envs: "$envs",
+          env: "$env",
         },
         totalAmount: {
           $sum: "$consumedTime",
@@ -98,7 +98,7 @@ async function getWeeklyReport(startDate, endDate, propertyName) {
       $project: {
         _id: 0,
         propertyName: "$_id.propertyName",
-        envs: "$_id.envs",
+        env: "$_id.env",
         totalAmount: "$totalAmount",
         count: "$count",
         avg: {
@@ -107,7 +107,7 @@ async function getWeeklyReport(startDate, endDate, propertyName) {
       },
     },
     {
-      $sort: { envs: 1 },
+      $sort: { env: 1 },
     },
   ]);
 }
diff --git a/packages/api/middlewares/authentication.js b/packages/api/middlewares/authentication.js
index ee3951f8..c750ae0a 100644
--- a/packages/api/middlewares/authentication.js
+++ b/packages/api/middlewares/authentication.js
@@ -4,6 +4,7 @@ const APIKeyService = require("../services/apiKeyService");
 const config = require("../config");
 const keyUtil = require("../utils/keyUtil");
 const jwtAuth = require("jsonwebtoken");
+const APIKey = require("../models/apiKey");
 const Unauthorized = require("../utils/errors/Unauthorized");
 
 module.exports = () => {
@@ -44,9 +45,19 @@ module.exports = () => {
       }
     };
 
-    const token = extractToken(req);
+    let token = extractToken(req);
     let error = false;
     let success = false;
+
+    try {
+      const result = await APIKey.findOne({ userId: token });
+      if (result != null) {
+        token = result.hashKey;
+      }
+    } catch (e) {
+      console.log(e);
+    }
+
     jwtAuth.verify(token, config.get("token:secret"), function (err, data) {
       if (err) {
         if (err.message != "invalid algorithm") {
diff --git a/packages/api/models/alias.js b/packages/api/models/alias.js
index 1c3b30cd..23d1232b 100644
--- a/packages/api/models/alias.js
+++ b/packages/api/models/alias.js
@@ -6,11 +6,15 @@ const alias = new mongoose.Schema({
     required: true,
     unique: true,
   },
-  property: {
+  propertyName: {
     type: String,
     required: false,
   },
-  name: {
+  propertyTitle: {
+    type: String,
+    required: false,
+  },
+  url: {
     type: String,
     required: false,
   },
@@ -26,11 +30,24 @@ const alias = new mongoose.Schema({
     type: String,
     required: false,
   },
+  createdBy: {
+    type: String,
+    required: false,
+  },
   createdAt: {
     type: Date,
     required: false,
   },
- 
+  updatedAt: {
+    type: Date,
+    required: false,
+  },
+  isActive: {
+    type: Boolean,
+    required: false,
+  },
 });
 
+alias.index({ propertyName: 1, env: 1 }, { unique: true });
+
 module.exports = mongoose.model("alias", alias);
diff --git a/packages/api/models/event.js b/packages/api/models/event.js
index 8561a2b1..74585825 100644
--- a/packages/api/models/event.js
+++ b/packages/api/models/event.js
@@ -25,7 +25,7 @@ const event = new mongoose.Schema({
     type: String,
     required: false,
   },
-  envs: {
+  env: {
     type: String,
     required: false,
   },
@@ -37,6 +37,14 @@ const event = new mongoose.Schema({
     type: String,
     required: false,
   },
+  url: {
+    type: String,
+    required: false,
+  },
+  path: {
+    type: String,
+    required: false,
+  },
   failure: {
     type: Boolean,
     required: false,
diff --git a/packages/api/models/eventTimeTrace.js b/packages/api/models/eventTimeTrace.js
index 6f47274f..118bee29 100644
--- a/packages/api/models/eventTimeTrace.js
+++ b/packages/api/models/eventTimeTrace.js
@@ -18,7 +18,7 @@ const eventTimeTrace = new mongoose.Schema({
     type: String,
     required: false,
   },
-  envs: {
+  env: {
     type: String,
     required: false,
   },
diff --git a/packages/api/routes/event.js b/packages/api/routes/event.js
index cf391923..c2d75e45 100644
--- a/packages/api/routes/event.js
+++ b/packages/api/routes/event.js
@@ -9,6 +9,8 @@ router.post("/fetch/analytics/all", analyticsServiceAll.analyticsServiceAll);
 
 router.post("/fetch/analytics/filter", analyticsServiceFilter.analyticsServiceFilter);
 
+router.get("/get/search/spa", getSearchResultForSPA.getSearchResultForSPA);
+
 router.get("/get/search/spa/:searchQuery", getSearchResultForSPA.getSearchResultForSPA);
 
 module.exports = router;
diff --git a/packages/api/routes/scripts/dataDump.js b/packages/api/routes/scripts/dataDump.js
index c4afe4d8..bcf1becd 100644
--- a/packages/api/routes/scripts/dataDump.js
+++ b/packages/api/routes/scripts/dataDump.js
@@ -3,11 +3,13 @@ const clearData = require("../../controllers/scripts/clearData");
 const eventDataDump = require("../../controllers/scripts/eventDataDump");
 const eventTimeMatricesDump = require("../../controllers/scripts/eventTimeMatricesDump");
 const webPropertyDataDump = require("../../controllers/scripts/webPropertyDataDump");
+const aliasDataDump = require("../../controllers/scripts/aliasDataDump");
 const router = new Router();
 
 router.post("/events", eventDataDump.eventDataDump);
 router.post("/eventstime", eventTimeMatricesDump.eventTimeMatricesDump);
 router.post("/webproperty", webPropertyDataDump.webPropertyDataDump);
+router.post("/alias", aliasDataDump.aliasDataDump);
 router.post("/remove", clearData.clearData);
 
 module.exports = router;
diff --git a/packages/api/routes/webProperty.js b/packages/api/routes/webProperty.js
index c32d6b97..14f226ee 100644
--- a/packages/api/routes/webProperty.js
+++ b/packages/api/routes/webProperty.js
@@ -25,4 +25,6 @@ router.post("/alias", saveAlias);
 
 router.get("/alias/list", getAliasList);
 
+router.get("/alias/list/:name", getAliasList);
+
 module.exports = router;
diff --git a/packages/api/services/deployService.js b/packages/api/services/deployService.js
index db22bc52..b49bbc7a 100644
--- a/packages/api/services/deployService.js
+++ b/packages/api/services/deployService.js
@@ -47,12 +47,12 @@ async function deploy({ name, spaArchive, appPath, ref, property, env } = {}) {
 
   //to check operator
   console.log("Checking the property is Operator or Baremetal : ");
-  const responseAlias = await alias.find({ property: property, env: env });
+  const responseAlias = await alias.find({ propertyName: property, env: env });
   if (responseAlias?.length > 0) {
     const operatorAlias = responseAlias[0]._doc;
     console.log(operatorAlias);
     if (operatorAlias?.type === "operator") {
-      const zipPath = await createSPAshipTemplateRequest(operatorAlias, name, appPath, tmpDir);
+      const zipPath = await createSPAshipTemplateRequest(operatorAlias, name, appPath, tmpDir, env);
 
       const formData = new FormData();
       try {
@@ -128,15 +128,15 @@ async function deploy({ name, spaArchive, appPath, ref, property, env } = {}) {
 
 module.exports = { deploy };
 
-async function createSPAshipTemplateRequest(operatorAlias, name, appPath, tmpDir) {
+async function createSPAshipTemplateRequest(operatorAlias, name, appPath, tmpDir, env) {
   if (appPath.charAt(0) == "/" && appPath.length === 1) appPath = ".";
   else if (appPath.charAt(0) == "/") appPath = appPath.substr(1);
   const spaShipFile = {
     websiteVersion: "v1",
-    websiteName: operatorAlias.property,
+    websiteName: operatorAlias.propertyName,
     name: name,
     mapping: appPath,
-    environments: [{ name: operatorAlias.namespace, updateRestriction: false, exclude: false }],
+    environments: [{ name: env, updateRestriction: false, exclude: false }],
   };
   console.log("Operator Config : ");
   console.log(spaShipFile);
@@ -146,13 +146,11 @@ async function createSPAshipTemplateRequest(operatorAlias, name, appPath, tmpDir
       await fs.writeFileSync(path.join(tmpDir, "dist/.spaship"), JSON.stringify(spaShipFile, null, "\t"));
       zipPath = path.join(tmpDir, "../SPAship" + uuid() + ".zip");
       await zip(path.join(tmpDir, "dist"), zipPath);
-    } 
-    else if (await fileExists(path.join(tmpDir, "build"))) {
+    } else if (await fileExists(path.join(tmpDir, "build"))) {
       await fs.writeFileSync(path.join(tmpDir, "build/.spaship"), JSON.stringify(spaShipFile, null, "\t"));
       zipPath = path.join(tmpDir, "../SPAship" + uuid() + ".zip");
       await zip(path.join(tmpDir, "build"), zipPath);
-    } 
-    else {
+    } else {
       await fs.writeFileSync(path.join(tmpDir, ".spaship"), JSON.stringify(spaShipFile, null, "\t"));
       zipPath = path.join(tmpDir, "../SPAship" + uuid() + ".zip");
       await zip(tmpDir, zipPath);


Test patch:
diff --git a/packages/api/controllers/webPropertyServices/getLatestActivities.js b/packages/api/controllers/webPropertyServices/getLatestActivities.js
index 1377ab7d..a6cb36f2 100644
--- a/packages/api/controllers/webPropertyServices/getLatestActivities.js
+++ b/packages/api/controllers/webPropertyServices/getLatestActivities.js
@@ -1,8 +1,8 @@
 const chart = require("../../models/event");
 
-const getLatestActivitiesService = async (request) => {
+const getLatestActivitiesService = async (matchRequest, limitRequest, skipRequest) => {
   try {
-    const response = await fetchLatestActivitiesByProperty(request);
+    const response = await fetchLatestActivitiesByProperty(matchRequest, limitRequest, skipRequest);
     bindResponse(response);
     return response;
   } catch (e) {
@@ -24,7 +24,7 @@ function bindResponse(response) {
   });
 }
 
-async function fetchLatestActivitiesByProperty(matchRequest) {
+async function fetchLatestActivitiesByProperty(matchRequest, limitRequest, skipRequest) {
   return await chart.aggregate([
     {
       $match: matchRequest,
@@ -40,20 +40,23 @@ async function fetchLatestActivitiesByProperty(matchRequest) {
         propertyName: "$propertyName",
         code: "$code",
         branch: "$branch",
-        envs: "$envs",
+        env: "$env",
         createdAt: "$createdAt",
         _id: 0,
       },
     },
     {
-      $limit: 15,
+      $limit: limitRequest.limit,
+    },
+    {
+      $skip: skipRequest.skip,
     },
   ]);
 }
 
 function actvitiesText(item, codeMap) {
   item.latestActivityHead = " has been " + item.code + " ";
-  item.latestActivityTail = " at " + item.createdAt.toString().slice(0, 24) + " in " + item.envs;
+  item.latestActivityTail = " at " + item.createdAt.toString().slice(0, 24) + " in " + item.env;
 }
 
 module.exports = { getLatestActivitiesService };