Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CloudComputing_Act1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Jesus Galaz Reyes
CloudComputing_Act1
Commits
6ac22994
Commit
6ac22994
authored
9 months ago
by
Rokas Stankunas
Browse files
Options
Downloads
Patches
Plain Diff
Implementing input sanitation for CRUD actions
parent
d4837dbd
No related branches found
No related tags found
1 merge request
!6
Adding toDo app functionability
Pipeline
#15729
passed
9 months ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
public/js/app.js
+20
-2
20 additions, 2 deletions
public/js/app.js
public/js/index.js
+18
-0
18 additions, 0 deletions
public/js/index.js
with
38 additions
and
2 deletions
public/js/app.js
+
20
−
2
View file @
6ac22994
//
Obtener
referenc
ia a los elementos del DOM
//
Get
referenc
e to DOM elements
const
taskList
=
document
.
querySelector
(
'
.task-list ul
'
);
const
taskList
=
document
.
querySelector
(
'
.task-list ul
'
);
const
newTaskForm
=
document
.
querySelector
(
'
form
'
);
const
newTaskForm
=
document
.
querySelector
(
'
form
'
);
...
@@ -78,7 +78,7 @@ newTaskForm.addEventListener('submit', async (e) => {
...
@@ -78,7 +78,7 @@ newTaskForm.addEventListener('submit', async (e) => {
const
newTodo
=
await
res
.
json
();
const
newTodo
=
await
res
.
json
();
taskList
.
appendChild
(
createTaskElement
(
newTodo
));
taskList
.
appendChild
(
createTaskElement
(
newTodo
));
input
.
value
=
''
;
//
Limpiar el campo de entrada
input
.
value
=
''
;
//
Clear input field
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
'
Error adding task:
'
,
err
);
console
.
error
(
'
Error adding task:
'
,
err
);
}
}
...
@@ -86,6 +86,12 @@ newTaskForm.addEventListener('submit', async (e) => {
...
@@ -86,6 +86,12 @@ newTaskForm.addEventListener('submit', async (e) => {
// Mark task as completed
// Mark task as completed
async
function
markAsDone
(
taskId
,
isDone
)
{
async
function
markAsDone
(
taskId
,
isDone
)
{
// Input sanitation
if
(
isNaN
(
parseInt
(
taskId
,
10
))
&&
typeof
(
isDone
)
===
'
boolean
'
)
{
console
.
error
(
'
Invalid task ID or task status is invalid
'
);
return
;
}
try
{
try
{
const
res
=
await
fetch
(
`/api/todos/
${
taskId
}
/done`
,
{
const
res
=
await
fetch
(
`/api/todos/
${
taskId
}
/done`
,
{
method
:
'
PUT
'
,
method
:
'
PUT
'
,
...
@@ -104,6 +110,12 @@ async function markAsDone(taskId, isDone) {
...
@@ -104,6 +110,12 @@ async function markAsDone(taskId, isDone) {
// Erase task
// Erase task
async
function
deleteTask
(
taskId
)
{
async
function
deleteTask
(
taskId
)
{
// Input sanitation
if
(
isNaN
(
parseInt
(
taskId
,
10
)))
{
console
.
error
(
'
Invalid task ID
'
);
return
;
}
try
{
try
{
const
res
=
await
fetch
(
`/api/todos/
${
taskId
}
`
,
{
const
res
=
await
fetch
(
`/api/todos/
${
taskId
}
`
,
{
method
:
'
DELETE
'
method
:
'
DELETE
'
...
@@ -122,6 +134,12 @@ async function deleteTask(taskId) {
...
@@ -122,6 +134,12 @@ async function deleteTask(taskId) {
// Edit task
// Edit task
async
function
updateTask
(
taskId
,
newDescription
)
{
async
function
updateTask
(
taskId
,
newDescription
)
{
// Input sanitation
if
(
isNaN
(
parseInt
(
taskId
,
10
))
&&
typeof
(
newDescription
)
===
'
string
'
)
{
console
.
error
(
'
Invalid task ID or new description is not string
'
);
return
;
}
try
{
try
{
const
res
=
await
fetch
(
`/api/todos/
${
taskId
}
/description`
,
{
const
res
=
await
fetch
(
`/api/todos/
${
taskId
}
/description`
,
{
method
:
'
PUT
'
,
method
:
'
PUT
'
,
...
...
This diff is collapsed.
Click to expand it.
public/js/index.js
+
18
−
0
View file @
6ac22994
...
@@ -118,6 +118,12 @@ document.addEventListener('DOMContentLoaded', async () => {
...
@@ -118,6 +118,12 @@ document.addEventListener('DOMContentLoaded', async () => {
// Function to alternate to the completed state
// Function to alternate to the completed state
async
function
toggleComplete
(
taskId
,
isDone
)
{
async
function
toggleComplete
(
taskId
,
isDone
)
{
// Input sanitation
if
(
isNaN
(
parseInt
(
taskId
,
10
))
&&
typeof
(
isDone
)
===
'
boolean
'
)
{
console
.
error
(
'
Invalid task ID or task status is invalid
'
);
return
;
}
try
{
try
{
const
res
=
await
fetch
(
`/api/todos/
${
taskId
}
/done`
,
{
const
res
=
await
fetch
(
`/api/todos/
${
taskId
}
/done`
,
{
method
:
'
PUT
'
,
method
:
'
PUT
'
,
...
@@ -134,6 +140,12 @@ document.addEventListener('DOMContentLoaded', async () => {
...
@@ -134,6 +140,12 @@ document.addEventListener('DOMContentLoaded', async () => {
// Function to eliminate a task
// Function to eliminate a task
async
function
deleteTask
(
taskId
)
{
async
function
deleteTask
(
taskId
)
{
// Input sanitation
if
(
isNaN
(
parseInt
(
taskId
,
10
)))
{
console
.
error
(
'
Invalid task ID
'
);
return
;
}
try
{
try
{
const
res
=
await
fetch
(
`/api/todos/
${
taskId
}
`
,
{
const
res
=
await
fetch
(
`/api/todos/
${
taskId
}
`
,
{
method
:
'
DELETE
'
method
:
'
DELETE
'
...
@@ -148,6 +160,12 @@ document.addEventListener('DOMContentLoaded', async () => {
...
@@ -148,6 +160,12 @@ document.addEventListener('DOMContentLoaded', async () => {
// Function to update the description of a task
// Function to update the description of a task
async
function
updateTask
(
taskId
,
newDescription
)
{
async
function
updateTask
(
taskId
,
newDescription
)
{
// Input sanitation
if
(
isNaN
(
parseInt
(
taskId
,
10
))
&&
typeof
(
newDescription
)
===
'
string
'
)
{
console
.
error
(
'
Invalid task ID or new description is not string
'
);
return
;
}
try
{
try
{
const
res
=
await
fetch
(
`/api/todos/
${
taskId
}
/description`
,
{
const
res
=
await
fetch
(
`/api/todos/
${
taskId
}
/description`
,
{
method
:
'
PUT
'
,
method
:
'
PUT
'
,
...
...
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