medgo-query-generator
v1.0.0-beta.0
Published
## generateSearch
Downloads
92
Readme
Important to do when using
generateSearch
You must provide a generated search function by using the setGenerateSearch
method of the package.
It must always have a default similar to the following.
For your custom generation you can do as many things as you want.
function generateSearch(query: any, key: any): string {
switch (key) {
case "jobProfiles":
return (
"jobprofiles:" +
query[key]
.map((e: any): string =>
e.job !== -1
? e.specialtys.length > 0
? e.specialtys
.map((spec: any): string =>
e.institutions && e.institutions.length > 0
? e.institutions.map((i: any): string =>
("" + e.job).concat(
spec !== -1
? "s" + spec + (i !== -1 ? "s" + i : "")
: i !== -1
? "ss" + i
: ""
)
)
: ("" + e.job).concat(spec !== -1 ? "s" + spec : "")
)
.join(",")
: e.institutions && e.institutions.length > 0
? e.institutions.map((i: any): string => ("" + e.job).concat(i !== -1 ? "ss" + i : ""))
: ""
: ""
)
.filter((e: any): boolean => e !== "")
.join(",")
);
default:
return "" + key + ":" + query[key];
}
}
formatterslist
you can extend the formatters list with the extendFormatterslist
method of the package.
here's a quick example
// value will be the value of the variable isRadhiAGoodGuy in this example
// values are always string.
function booleanParser(value: string) {
return value === "true";
}
const formatterslist = {
isRadhiAGoodGuy: booleanParser
};
// Will do an object assign to add the new values you're using on top of the other parsers already defined in the package (check below for more)
extendFormatterslist(formatterslist);
List of formatters present in the module
let formatterslist = {
statut: splitStringAndParseInt,
job: splitStringAndParseInt,
jobProfilesPending: jobProfileParser2,
specialty: splitStringAndParseInt,
institution: splitStringAndParseInt,
admin: splitStringAndParseInt,
missionmotifcreationcategory: splitStringAndParseInt,
originInstitution: splitStringAndParseInt,
mission: splitStringAndParseInt,
id: splitStringAndParseInt,
worker: splitStringAndParseInt,
beginAt: unixRangeParser,
endAt: operatorNumberParser,
createdAt: operatorNumberParser,
jobprofiles: jobProfileParser,
searchname: searchNameParser,
populate: splitString,
isDeletedFromNetwork: booleanParser,
isDeletedFromNetworkByInstitutions: isDeletedFromNetworkParser,
isCanceled: booleanParser,
isFullTime: booleanParser,
isExpress: booleanParser,
isLongMission: booleanParser,
isPastMission: booleanParser,
isPlanning: booleanParser,
isValidated: booleanParser,
isFilled: booleanParser,
isNight: idBooleanParser,
isDay: idBooleanParser,
isDayRefused: idBooleanParser,
isNightRefused: idBooleanParser,
isSignedPerAdmin: booleanParser,
isSignedPerWorker: booleanParser,
isBlockedByAdmin: institutionServiceBooleanParser,
isRefusedByWorker: institutionServiceBooleanParser,
isWorkerNotified: idBooleanParser,
isAllowedDay: idBooleanParser,
isAllowedNight: idBooleanParser,
isAllowedService: institutionServiceBooleanParser,
service: splitStringAndParseInt,
range: rangeParser,
rangeBeginAt: rangeParser,
nbPotentialWorkers: operatorNumberParser,
isAccepted: booleanParser,
isRefused: booleanParser,
acceptedBy: splitStringAndParseInt,
createdBy: splitStringAndParseInt,
idInInstitution: splitStringAndParseInt,
isViaEmailCSVOption: booleanParser,
isPoleCSVOption: booleanParser,
isRecupCSVOption: booleanParser,
isTwoLinesForMissionOnTwoDaysCSVOption: booleanParser,
idInfoOnWorkersCSVOption: splitStringAndParseInt,
inCluster: splitStringAndParseInt,
didWorkerSignUp: booleanParser,
contract: splitStringAndParseInt,
isCancelled: booleanParser,
isFused: booleanParser,
isSigned: booleanParser,
isCancelledOrFused: booleanParser,
isSignedOrNew: booleanParser
};
For more information please check the source code to see how parsers work
Luxury
there's also an express middlware to put the req.query
request parameters in req.parameters
after parse with your configuration.