Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
simcaq-node
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
simcaq
simcaq-node
Merge requests
!98
[ci skip]Create matchQueries middleware
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
[ci skip]Create matchQueries middleware
match_queries_middleware
into
development
Overview
0
Commits
1
Pipelines
1
Changes
1
Closed
Vytor Calixto
requested to merge
match_queries_middleware
into
development
7 years ago
Overview
0
Commits
1
Pipelines
1
Changes
1
Expand
0
0
Merge request reports
Compare
development
version 1
fd1f325a
7 years ago
development (base)
and
latest version
latest version
fd1f325a
1 commit,
5 years ago
version 1
fd1f325a
1 commit,
7 years ago
1 file
+
41
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/libs/middlewares/matchQueries.js
0 → 100644
+
41
−
0
Options
// Retorna um array de "tuplas" com objetos que são iguais em duas queries distintas, com exceçã do valor total
function
matchQueries
(
queryA
=
[],
queryB
=
[])
{
match
=
[];
// Para cada objeto na query A
queryA
.
forEach
((
result
)
=>
{
// Obtém as chaves do objeto
let
keys
=
Object
.
keys
(
result
);
// Remove o total
let
index
=
keys
.
indexOf
(
'
total
'
);
if
(
index
>
-
1
)
keys
.
splice
(
index
,
1
);
let
objMatch
=
null
;
// Busca um objeto igual na query B
for
(
let
i
=
0
;
i
<
queryB
.
length
;
++
i
)
{
let
partialMatch
=
queryB
[
i
];
let
foundMatch
=
true
;
for
(
let
j
=
0
;
j
<
keys
.
length
;
++
j
)
{
let
key
=
keys
[
j
];
// Se diferem, não são um match
if
(
partialMatch
[
key
]
!==
result
[
key
])
{
foundMatch
=
false
;
break
;
}
}
// Se encontrou, pode parar
if
(
foundMatch
)
{
objMatch
=
partialMatch
;
break
;
}
}
// Inclui um array com os dois objetos dentro do array de matches
if
(
objMatch
)
{
match
.
push
([
result
,
objMatch
]);
}
});
return
match
;
}
module
.
exports
=
matchQueries
;
\ No newline at end of file
Loading