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
Merge requests
!11
Issue#7: ADD All routes, create route broken
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue#7: ADD All routes, create route broken
issue-7/implants-crud
into
develop
Overview
0
Commits
1
Pipelines
0
Changes
3
Merged
RICARDO PRADO FARIA
requested to merge
issue-7/implants-crud
into
develop
2 months ago
Overview
0
Commits
1
Pipelines
0
Changes
3
Expand
0
0
Merge request reports
Compare
develop
develop (base)
and
latest version
latest version
4118163e
1 commit,
2 months ago
3 files
+
126
−
10
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
src/handlers/implants.ts
+
107
−
0
Options
import
{
type
Request
,
type
Response
}
from
'
express
'
;
import
{
implants
}
from
'
@/db/schema
'
;
import
{
db
}
from
"
@/db
"
;
import
{
eq
}
from
'
drizzle-orm
'
;
import
{
implantSchema
}
from
'
@/validators/implantsValidator
'
;
export
default
class
implant
{
static
implantRequestValidation
(
req
:
Request
){
const
validation
=
implantSchema
.
safeParse
(
req
.
body
);
return
validation
.
success
;
}
static
implantRequestUnzip
(
req
:
Request
){
return
implantSchema
.
safeParse
(
req
.
body
);
}
static
async
getImplant
(
id
:
number
){
const
searched
=
await
db
.
select
().
from
(
implants
).
where
(
eq
(
implants
.
id
,
id
)).
limit
(
1
);
return
searched
[
0
]
||
null
;
}
static
async
implantRead
(
id
:
number
,
req
:
Request
,
res
:
Response
){
if
(
!
this
.
implantRequestValidation
(
req
))
{
return
res
.
status
(
400
).
json
({
error
:
"
Invalid Request
"
});
}
const
holder
=
await
this
.
getImplant
(
id
);
if
(
!
holder
)
{
return
res
.
status
(
404
).
json
({
error
:
"
Not Found
"
});
}
return
res
.
status
(
200
).
json
(
holder
);
}
static
async
implantUpdate
(
id
:
number
,
req
:
Request
,
res
:
Response
){
if
(
!
this
.
implantRequestValidation
(
req
))
{
return
res
.
status
(
400
).
json
({
error
:
"
Invalid Request
"
});
}
const
updated_implant
=
await
this
.
getImplant
(
id
);
if
(
!
updated_implant
)
{
return
res
.
status
(
404
).
json
({
error
:
"
Not Found
"
});
}
const
updates
:
Partial
<
typeof
implants
.
$inferInsert
>
=
{
name
:
req
.
body
.
name
||
updated_implant
.
name
,
price
:
req
.
body
.
price
||
updated_implant
.
price
,
cyberCost
:
req
.
body
.
cyberCost
||
updated_implant
.
cyberCost
,
bodyPart
:
req
.
body
.
bodyPart
||
updated_implant
.
bodyPart
,
};
try
{
await
db
.
update
(
implants
).
set
(
updates
).
where
(
eq
(
implants
.
id
,
id
));
}
catch
(
error
)
{
return
res
.
status
(
500
).
json
({
error
:
"
Update User Error
"
})
}
return
res
.
status
(
200
).
json
({
message
:
"
OK
"
});
}
static
async
implantDelete
(
id
:
number
,
req
:
Request
,
res
:
Response
){
if
(
!
this
.
implantRequestValidation
(
req
))
{
return
res
.
status
(
400
).
json
(
"
Invalid Request
"
);
}
if
(
!
this
.
getImplant
(
id
))
{
return
res
.
status
(
404
).
json
(
"
Not Found
"
);
}
try
{
await
db
.
delete
(
implants
).
where
(
eq
(
implants
.
id
,
id
));
return
res
.
status
(
200
).
json
({
message
:
"
Implant removed successfully
"
});
}
catch
(
error
)
{
return
res
.
status
(
500
).
json
({
error
:
"
Implant Removal Error
"
});
}
}
static
async
implantCreate
(
req
:
Request
,
res
:
Response
){
const
implant_package
=
this
.
implantRequestUnzip
(
req
);
if
(
!
implant_package
.
success
)
{
return
res
.
status
(
400
).
json
(
"
Invalid Request
"
);
}
const
{
name
,
price
,
cyberCost
,
bodyPart
}
=
implant_package
.
data
;
try
{
const
brand_new
=
await
db
.
insert
(
implants
).
values
({
name
,
price
,
cyberCost
,
bodyPart
,
}).
returning
();
return
res
.
status
(
200
).
json
({
message
:
"
Implant Creation Successfull
"
,
implant
:
brand_new
});
}
catch
(
error
)
{
return
res
.
status
(
500
).
json
({
error
:
"
User Creation Error
"
});
}
}
}
Loading