Improve parseQueryParams regex
This commit is contained in:
parent
aa0c09ac82
commit
2c2eb69ae7
|
@ -113,29 +113,20 @@ module MongoDBModule {
|
|||
}
|
||||
|
||||
parseQueryParams(params: string, mode: string) {
|
||||
let queryParams = params.split(/(?<=(},)).*{/g)
|
||||
let group1 = queryParams[0]
|
||||
let group2 = queryParams[2]
|
||||
let group3 = queryParams[4]
|
||||
if (group1) {
|
||||
group1 = JSON.parse(group1.replace(/,+$/, ""))
|
||||
}
|
||||
if (group2) {
|
||||
group2 = JSON.parse("{" + group2.replace(/,+$/, ""))
|
||||
}
|
||||
if (group3) {
|
||||
group3 = JSON.parse("{" + group3.replace(/,+$/, ""))
|
||||
}
|
||||
let queryParams = params.split(/(?<=}),[\n\s]*(?={)/g)
|
||||
let group1 = queryParams[0] ? JSON.parse(queryParams[0]) : {}
|
||||
let group2 = queryParams[1] ? JSON.parse(queryParams[1]) : {}
|
||||
let group3 = queryParams[2] ? JSON.parse(queryParams[2]) : {}
|
||||
if (mode === "update") {
|
||||
return {
|
||||
filter: group1,
|
||||
update: group2,
|
||||
options: group3 ?? {},
|
||||
options: group3,
|
||||
}
|
||||
}
|
||||
return {
|
||||
filter: group1,
|
||||
options: group2 ?? {},
|
||||
options: group2,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue