Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
node_crisp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
web
node_crisp
Commits
ba1cb95c
Commit
ba1cb95c
authored
Aug 19, 2021
by
Gabriel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cambia orden de provincias
parent
01577297
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
15 deletions
+12
-15
is.js
endpoints/is.js
+12
-15
No files found.
endpoints/is.js
View file @
ba1cb95c
const
config
=
require
(
'config'
);
const
config
=
require
(
'config'
);
const
axios
=
require
(
'axios'
);
const
axios
=
require
(
'axios'
);
let
_
=
require
(
'lodash'
);
var
AUTH_TOKEN
=
config
.
get
(
'credenciales.isApiToken'
);
var
AUTH_TOKEN
=
config
.
get
(
'credenciales.isApiToken'
);
...
@@ -8,21 +9,17 @@ let isClient = axios.create({
...
@@ -8,21 +9,17 @@ let isClient = axios.create({
headers
:
{
'Authorization'
:
`Bearer
${
AUTH_TOKEN
}
`
}
headers
:
{
'Authorization'
:
`Bearer
${
AUTH_TOKEN
}
`
}
});
});
function
sortProvinciasById
(
provincias
)
{
const
CABA
=
"CIUDAD AUTONOMA DE BUENOS AIRES"
;
let
ids
=
[];
const
BUENOS_AIRES
=
"BUENOS AIRES"
;
for
(
let
i
=
0
;
i
<
provincias
.
length
;
i
++
)
{
const
MISIONES
=
"MISIONES"
;
ids
.
push
(
provincias
[
i
].
id_provincia
);
}
ids
.
sort
(
function
(
a
,
b
)
{
function
sortProvinciasByName
(
provincias
){
return
parseInt
(
a
)
-
parseInt
(
b
)
//Orden alfabetico, pero con (1) CABA, (2) Buenos Aires y (3) Misiones al principio
});
let
provinciasByName
=
_
.
orderBy
(
provincias
,
[
provincia
=>
provincia
.
descripcion
],
[
'asc'
]);
provinciasByName
=
_
.
sortBy
(
provinciasByName
,
({
descripcion
})
=>
descripcion
===
MISIONES
?
0
:
1
);
let
sortedProvincias
=
[];
provinciasByName
=
_
.
sortBy
(
provinciasByName
,
({
descripcion
})
=>
descripcion
===
BUENOS_AIRES
?
0
:
1
);
for
(
let
i
=
0
;
i
<
ids
.
length
;
i
++
)
{
provinciasByName
=
_
.
sortBy
(
provinciasByName
,
({
descripcion
})
=>
descripcion
===
CABA
?
0
:
1
);
sortedProvincias
.
push
(
getProvinciaById
(
provincias
,
ids
[
i
]));
return
provinciasByName
;
}
return
sortedProvincias
;
}
}
function
getProvinciaById
(
provincias
,
id
)
{
function
getProvinciaById
(
provincias
,
id
)
{
...
@@ -39,7 +36,7 @@ module.exports =
...
@@ -39,7 +36,7 @@ module.exports =
return
await
isClient
.
get
(
'provincias/atencion'
)
return
await
isClient
.
get
(
'provincias/atencion'
)
.
then
(
async
function
(
response
)
{
.
then
(
async
function
(
response
)
{
let
provincias
=
response
.
data
;
let
provincias
=
response
.
data
;
return
sortProvinciasBy
Id
(
provincias
);
return
sortProvinciasBy
Name
(
provincias
);
})
})
.
catch
(
function
(
error
)
{
.
catch
(
function
(
error
)
{
console
.
log
(
error
);
console
.
log
(
error
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment