Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
treinamento-2025.1-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Harbor 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
RICARDO PRADO FARIA
treinamento-2025.1-backend
Commits
c1a8a7ba
Commit
c1a8a7ba
authored
2 months ago
by
Amanda Pollyanna da Silva Rodrigues
Browse files
Options
Downloads
Patches
Plain Diff
FIX implants handlers
parent
9c129caf
Branches
Branches containing commit
No related tags found
1 merge request
!17
FIX implants handlers
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/handlers/implants.ts
+32
-14
32 additions, 14 deletions
src/handlers/implants.ts
src/handlers/user.ts
+2
-2
2 additions, 2 deletions
src/handlers/user.ts
with
34 additions
and
16 deletions
src/handlers/implants.ts
+
32
−
14
View file @
c1a8a7ba
...
...
@@ -2,11 +2,11 @@ import { type Request, type Response } from 'express';
import
{
implantsTable
}
from
'
@/db/schema
'
;
import
{
db
}
from
"
@/db
"
;
import
{
eq
}
from
'
drizzle-orm
'
;
import
{
implantSchema
}
from
'
@/validators/implantsValidator
'
;
import
{
implantSchema
,
updateImplantSchema
}
from
'
@/validators/implantsValidator
'
;
export
default
class
implant
{
static
implantRequestValidation
(
req
:
Request
){
const
validation
=
i
mplantSchema
.
safeParse
(
req
.
body
);
const
validation
=
updateI
mplantSchema
.
safeParse
(
req
.
body
);
return
validation
.
success
;
}
...
...
@@ -19,13 +19,19 @@ export default class implant{
return
searched
[
0
]
||
null
;
}
static
async
implantRead
(
id
:
number
,
req
:
Request
,
res
:
Response
){
if
(
!
this
.
implantRequestValidation
(
req
))
static
async
implantRead
(
req
:
Request
,
res
:
Response
){
if
(
!
implant
.
implantRequestValidation
(
req
))
{
return
res
.
status
(
400
).
json
({
error
:
"
Invalid Request
"
});
}
const
holder
=
await
this
.
getImplant
(
id
);
const
{
id
}
=
req
.
params
;
const
parsedId
=
parseInt
(
id
,
10
);
if
(
isNaN
(
parsedId
))
{
return
res
.
status
(
400
).
json
({
error
:
"
ID inválido
"
});
}
const
holder
=
await
implant
.
getImplant
(
parsedId
);
if
(
!
holder
)
{
return
res
.
status
(
404
).
json
({
error
:
"
Not Found
"
});
...
...
@@ -35,13 +41,19 @@ export default class implant{
}
static
async
implantUpdate
(
id
:
number
,
req
:
Request
,
res
:
Response
){
if
(
!
this
.
implantRequestValidation
(
req
))
static
async
implantUpdate
(
req
:
Request
,
res
:
Response
){
if
(
!
implant
.
implantRequestValidation
(
req
))
{
return
res
.
status
(
400
).
json
({
error
:
"
Invalid Request
"
});
}
const
updated_implant
=
await
this
.
getImplant
(
id
);
const
{
id
}
=
req
.
params
;
const
parsedId
=
parseInt
(
id
,
10
);
if
(
isNaN
(
parsedId
))
{
return
res
.
status
(
400
).
json
({
error
:
"
ID inválido
"
});
}
const
updated_implant
=
await
implant
.
getImplant
(
parsedId
);
if
(
!
updated_implant
)
{
return
res
.
status
(
404
).
json
({
error
:
"
Not Found
"
});
...
...
@@ -55,7 +67,7 @@ export default class implant{
};
try
{
await
db
.
update
(
implantsTable
).
set
(
updates
).
where
(
eq
(
implantsTable
.
id
,
i
d
));
await
db
.
update
(
implantsTable
).
set
(
updates
).
where
(
eq
(
implantsTable
.
id
,
parsedI
d
));
}
catch
(
error
)
{
return
res
.
status
(
500
).
json
({
error
:
"
Update User Error
"
})
}
...
...
@@ -63,19 +75,25 @@ export default class implant{
return
res
.
status
(
200
).
json
({
message
:
"
OK
"
});
}
static
async
implantDelete
(
id
:
number
,
req
:
Request
,
res
:
Response
){
if
(
!
this
.
implantRequestValidation
(
req
))
static
async
implantDelete
(
req
:
Request
,
res
:
Response
){
if
(
!
implant
.
implantRequestValidation
(
req
))
{
return
res
.
status
(
400
).
json
(
"
Invalid Request
"
);
}
if
(
!
this
.
getImplant
(
id
))
const
{
id
}
=
req
.
params
;
const
parsedId
=
parseInt
(
id
,
10
);
if
(
isNaN
(
parsedId
))
{
return
res
.
status
(
400
).
json
({
error
:
"
ID inválido
"
});
}
if
(
!
implant
.
getImplant
(
parsedId
))
{
return
res
.
status
(
404
).
json
(
"
Not Found
"
);
}
try
{
await
db
.
delete
(
implantsTable
).
where
(
eq
(
implantsTable
.
id
,
i
d
));
await
db
.
delete
(
implantsTable
).
where
(
eq
(
implantsTable
.
id
,
parsedI
d
));
return
res
.
status
(
200
).
json
({
message
:
"
Implant removed successfully
"
});
}
catch
(
error
)
{
return
res
.
status
(
500
).
json
({
error
:
"
Implant Removal Error
"
});
...
...
@@ -83,7 +101,7 @@ export default class implant{
}
static
async
implantCreate
(
req
:
Request
,
res
:
Response
){
const
implant_package
=
this
.
implantRequestUnzip
(
req
);
const
implant_package
=
implant
.
implantRequestUnzip
(
req
);
setInterval
if
(
!
implant_package
.
success
)
{
return
res
.
status
(
400
).
json
(
"
Invalid Request
"
);
...
...
This diff is collapsed.
Click to expand it.
src/handlers/user.ts
+
2
−
2
View file @
c1a8a7ba
...
...
@@ -133,7 +133,7 @@ export default class User{
static
readUser
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
any
>
=>
{
try
{
// extrair id
e nome
da requisição
// extrair id da requisição
const
{
id
}
=
req
.
params
;
// converter id para número
...
...
@@ -182,7 +182,7 @@ export default class User{
return
res
.
status
(
401
).
json
({
message
:
'
Senha incorreta
'
});
}
//
criar
chave secreta para assinar e validar tokens
, guardar no .env
//
acessar no .env a
chave secreta para assinar e validar tokens
const
jwtSecret
=
process
.
env
[
"
APP_SECRET
"
];
if
(
!
jwtSecret
)
{
return
res
.
status
(
500
).
json
({
error
:
"
Chave secreta do JWT não configurada
"
});
...
...
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