Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
repp_backend
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
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
Julieta Dubra Raimunde
repp_backend
Commits
61415de7
Commit
61415de7
authored
3 years ago
by
Renzo Beux
Browse files
Options
Downloads
Patches
Plain Diff
fix: validate for numbers on all rows
parent
dfa337ab
Branches
feature/sheetParserFixes
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Services/SheetService.ts
+28
-0
28 additions, 0 deletions
src/Services/SheetService.ts
with
28 additions
and
0 deletions
src/Services/SheetService.ts
+
28
−
0
View file @
61415de7
...
...
@@ -86,6 +86,22 @@ const getLiteralGroup = (age: number): string => {
return
`
${
age
}
`
;
};
const
validator
=
(
instance
:
any
)
=>
{
if
(
typeof
instance
.
edad
!==
'
number
'
)
{
throw
new
Error
(
'
Edad should be a number
'
);
}
else
if
(
instance
.
peso
!==
undefined
)
{
if
(
typeof
instance
.
peso
!==
'
number
'
)
{
throw
new
Error
(
'
Peso should be a number
'
);
}
}
else
if
(
instance
.
talla
!==
undefined
)
{
if
(
typeof
instance
.
talla
!==
'
number
'
)
{
throw
new
Error
(
'
Talla should be a number
'
);
}
}
else
{
throw
new
Error
(
'
A row must have either Peso or Talla
'
);
}
};
/* EXPORT FUNCTIONS */
const
parseSheetService
=
(
data
:
Buffer
):
AgeGroupJSON
[]
=>
{
...
...
@@ -129,6 +145,10 @@ const parseSheetService = (data: Buffer): AgeGroupJSON[] => {
// elemnts on auxObj
hombresMenores
.
forEach
((
item
)
=>
{
if
(
item
===
null
)
throw
new
Error
(
'
Item is null
'
);
validator
(
item
);
if
(
item
.
edad
>
12
)
{
throw
new
Error
(
'
Edad should be less than 12 months
'
);
}
const
bridge
:
string
=
(
item
.
edad
).
toString
();
auxObj
[
bridge
]
=
auxObj
[
bridge
]
?
auxObj
[
bridge
]
:
[];
(
auxObj
[
bridge
]).
push
(
item
.
peso
);
...
...
@@ -149,6 +169,10 @@ const parseSheetService = (data: Buffer): AgeGroupJSON[] => {
mujeresMenores
.
forEach
((
item
)
=>
{
if
(
item
===
null
)
throw
new
Error
(
'
Item is null
'
);
validator
(
item
);
if
(
item
.
edad
>
12
)
{
throw
new
Error
(
'
Edad should be less than 12 months
'
);
}
const
bridge
:
string
=
(
item
.
edad
).
toString
();
auxObj
[
bridge
]
=
auxObj
[
bridge
]
?
auxObj
[
bridge
]
:
[];
(
auxObj
[
bridge
]).
push
(
item
.
peso
);
...
...
@@ -169,6 +193,8 @@ const parseSheetService = (data: Buffer): AgeGroupJSON[] => {
auxObj
=
{};
hombres
.
forEach
((
item
)
=>
{
if
(
item
===
null
)
throw
new
Error
(
'
Item is null
'
);
validator
(
item
);
const
bridge
:
string
=
getLiteralGroup
(
item
.
edad
);
auxObj
[
bridge
]
=
auxObj
[
bridge
]
?
auxObj
[
bridge
]
:
[];
let
peso
;
...
...
@@ -197,6 +223,8 @@ const parseSheetService = (data: Buffer): AgeGroupJSON[] => {
auxObj
=
{};
mujeres
.
forEach
((
item
)
=>
{
if
(
item
===
null
)
throw
new
Error
(
'
Item is null
'
);
validator
(
item
);
const
bridge
:
string
=
getLiteralGroup
(
item
.
edad
);
auxObj
[
bridge
]
=
auxObj
[
bridge
]
?
auxObj
[
bridge
]
:
[];
let
peso
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment