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
1ae35809
Commit
1ae35809
authored
2 months ago
by
Ricardo
Browse files
Options
Downloads
Plain Diff
Merge branch 'develop' of gitlab.c3sl.ufpr.br:rpf23/treinamento-2025.1-backend into develop
parents
fde52122
56c72032
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/handlers/user.ts
+5
-6
5 additions, 6 deletions
src/handlers/user.ts
src/index.ts
+1
-1
1 addition, 1 deletion
src/index.ts
src/validators/userValidator.ts
+4
-1
4 additions, 1 deletion
src/validators/userValidator.ts
with
10 additions
and
8 deletions
src/handlers/user.ts
+
5
−
6
View file @
1ae35809
import
{
type
Request
,
type
Response
}
from
'
express
'
;
import
{
userSchema
}
from
"
@/validators/userValidator
"
;
import
{
userSchema
,
updateUserSchema
}
from
"
@/validators/userValidator
"
;
import
{
db
}
from
"
@/db
"
;
import
{
or
,
eq
}
from
'
drizzle-orm
'
;
import
{
eq
}
from
'
drizzle-orm
'
;
import
{
usersTable
}
from
"
@/db/schema
"
;
import
bcrypt
from
"
bcrypt
"
;
import
jwt
from
'
jsonwebtoken
'
;
...
...
@@ -114,7 +114,7 @@ export default class User{
try
{
// extrair id e nome da requisição
const
{
id
,
name
}
=
req
.
params
;
const
{
id
}
=
req
.
params
;
// converter id para número
const
parsedId
=
parseInt
(
id
,
10
);
...
...
@@ -123,14 +123,13 @@ export default class User{
}
// validar com o Zod
const
parsedData
=
userSchema
.
safeParse
({
id
:
parsedId
,
name
});
const
parsedData
=
u
pdateU
serSchema
.
safeParse
({
id
:
parsedId
});
if
(
!
parsedData
.
success
)
{
return
res
.
status
(
400
).
json
({
error
:
"
Dados Inválidos
"
,
details
:
parsedData
.
error
.
errors
});
}
const
result
=
await
db
.
select
().
from
(
usersTable
)
.
where
(
or
(
eq
(
usersTable
.
id
,
parsedId
),
eq
(
usersTable
.
name
,
name
)))
.
limit
(
1
);
.
where
(
eq
(
usersTable
.
id
,
parsedId
)
).
limit
(
1
);
if
(
result
.
length
===
0
)
{
// array vazio
return
res
.
status
(
404
).
json
({
error
:
"
Usuário não encontrado
"
});
}
...
...
This diff is collapsed.
Click to expand it.
src/index.ts
+
1
−
1
View file @
1ae35809
...
...
@@ -15,7 +15,7 @@ app.use(json())
// Rotas de usuário
app
.
post
(
'
/addUser
'
,
User
.
createUser
)
app
.
get
(
'
/getUser
'
,
User
.
readUser
)
app
.
get
(
'
/getUser
/:id
'
,
User
.
readUser
)
app
.
post
(
'
/loginUser
'
,
User
.
loginUser
)
app
.
put
(
'
/updateUser/:id
'
,
tokenAuthenticator
,
User
.
updateUser
)
app
.
delete
(
'
/deleteUser/:id
'
,
tokenAuthenticator
,
User
.
deleteUser
)
...
...
This diff is collapsed.
Click to expand it.
src/validators/userValidator.ts
+
4
−
1
View file @
1ae35809
...
...
@@ -11,3 +11,6 @@ export const userSchema = z.object({
cyberpsychosis
:
z
.
number
(),
// a definir restrições de validação
cyberLimit
:
z
.
number
(),
});
// Esquema de validação para atualização (todos os campos opcionais)
export
const
updateUserSchema
=
userSchema
.
partial
()
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