Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
perf(plugins/convert-date-param-operator): use object over switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Dec 2, 2023
1 parent 114075a commit 5d0895c
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/plugins/convert-date-param-operator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

const fp = require("fastify-plugin");

const operatorMap = {
ap: "=",
eb: "<",
eq: "=",
ge: ">=",
gt: ">",
le: "<=",
lt: "<",
ne: "!=",
sa: ">",
};

/**
* @author Frazer Smith
* @description Plugin that decorates Fastify instance with `convertDateParamOperator` function,
Expand All @@ -11,34 +23,12 @@ const fp = require("fastify-plugin");
async function plugin(server) {
/**
* @author Frazer Smith
* @author NextGen Healthcare
* @description Converts date param operator to corresponding value.
* @param {string} operator - Date param operator, in any letter case.
* @returns {string} converted date param operator.
*/
function convDateParamOperator(operator) {
switch (operator.toLowerCase()) {
case "ap":
return "=";
case "eb":
return "<";
case "eq":
return "=";
case "ge":
return ">=";
case "gt":
return ">";
case "le":
return "<=";
case "lt":
return "<";
case "ne":
return "!=";
case "sa":
return ">";
default:
return "=";
}
return operatorMap[operator.toLowerCase()] || "=";
}

server.decorate("convertDateParamOperator", convDateParamOperator);
Expand Down

0 comments on commit 5d0895c

Please sign in to comment.