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
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
0d3e7e8e
Commit
0d3e7e8e
authored
4 months ago
by
Amanda Pollyanna da Silva Rodrigues
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#6
ADD read user route
parent
0780828f
No related branches found
No related tags found
1 merge request
!7
Issue #6 ADD read user route
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/handlers/user.ts
+26
-1
26 additions, 1 deletion
src/handlers/user.ts
src/index.ts
+2
-1
2 additions, 1 deletion
src/index.ts
with
28 additions
and
2 deletions
src/handlers/user.ts
+
26
−
1
View file @
0d3e7e8e
import
{
type
Request
,
type
Response
}
from
'
express
'
;
import
{
type
Request
,
type
Response
}
from
'
express
'
;
import
{
userSchema
}
from
"
@/validators/userValidator
"
;
import
{
userSchema
}
from
"
@/validators/userValidator
"
;
import
{
db
}
from
"
@/db
"
;
import
{
db
}
from
"
@/db
"
;
import
{
eq
}
from
'
drizzle-orm
'
;
import
{
or
,
eq
}
from
'
drizzle-orm
'
;
import
{
usersTable
}
from
"
@/db/schema
"
;
import
{
usersTable
}
from
"
@/db/schema
"
;
import
bcrypt
from
"
bcryptjs
"
;
import
bcrypt
from
"
bcryptjs
"
;
import
{
z
}
from
'
zod
'
;
import
{
z
}
from
'
zod
'
;
...
@@ -109,3 +109,28 @@ export const createUser = async (req: Request, res: Response) => {
...
@@ -109,3 +109,28 @@ export const createUser = async (req: Request, res: Response) => {
return
res
.
status
(
500
).
json
({
error
:
"
Erro ao inserir o usuário. Por favor, tente novamente mais tarde.
"
});
return
res
.
status
(
500
).
json
({
error
:
"
Erro ao inserir o usuário. Por favor, tente novamente mais tarde.
"
});
}
}
};
};
export
const
readUser
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
const
{
id
,
nome
}
=
req
.
params
;
//extracao da requisicao
const
parsedData
=
userSchema
.
safeParse
({
id
,
nome
});
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
,
id
),
eq
(
usersTable
.
nome
,
nome
))).
limit
(
1
);
if
(
result
.
length
===
0
)
{
//array vazio
return
res
.
status
(
404
).
json
({
error
:
"
Usuário não encontrado
"
});
}
delete
result
[
0
].
password
;
return
res
.
status
(
200
).
json
(
result
[
0
]);
}
catch
(
error
)
{
console
.
error
(
error
);
return
res
.
status
(
500
).
json
({
error
:
"
Erro ao buscar o usuário. Por favor, tente novamente mais tarde.
"
});
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/index.ts
+
2
−
1
View file @
0d3e7e8e
import
express
,
{
urlencoded
,
json
}
from
'
express
'
import
express
,
{
urlencoded
,
json
}
from
'
express
'
import
dotenv
from
'
dotenv
'
import
dotenv
from
'
dotenv
'
import
{
createUser
}
from
'
./handlers/user
'
;
import
{
createUser
,
readUser
}
from
'
./handlers/user
'
;
import
Implant
from
'
@/handlers/implants
'
import
Implant
from
'
@/handlers/implants
'
import
{
Auth
}
from
'
@/middleware/auth
'
import
{
Auth
}
from
'
@/middleware/auth
'
...
@@ -15,6 +15,7 @@ app.use(json())
...
@@ -15,6 +15,7 @@ app.use(json())
// Rotas de usuário
// Rotas de usuário
app
.
post
(
'
/addUser
'
,
createUser
)
app
.
post
(
'
/addUser
'
,
createUser
)
app
.
get
(
'
/getUser
'
,
readUser
)
// Definir a porta e iniciar o servidor
// Definir a porta e iniciar o servidor
const
PORT
=
process
.
env
[
'
PORT
'
]
||
3000
const
PORT
=
process
.
env
[
'
PORT
'
]
||
3000
...
...
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