Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
H
hw88AlenBolatov
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Болатов Ален
hw88AlenBolatov
Commits
f0a6ca24
Commit
f0a6ca24
authored
Mar 16, 2023
by
Болатов Ален
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added update func in generic controller
parent
3a2941ee
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
0 deletions
+18
-0
Generic.ts
backend/src/controllers/Generic.ts
+15
-0
Location.ts
backend/src/routes/Location.ts
+1
-0
category.ts
backend/src/routes/category.ts
+2
-0
No files found.
backend/src/controllers/Generic.ts
View file @
f0a6ca24
...
...
@@ -67,9 +67,24 @@ const deleteDoc = (model: Model<any>) => (req: Request, res: Response) => {
});
};
const
update
=
(
model
:
Model
<
any
>
)
=>
(
req
:
Request
,
res
:
Response
)
=>
{
const
id
=
req
.
params
.
id
;
const
data
=
{...
req
.
body
};
model
.
findByIdAndUpdate
(
id
,
data
)
.
then
((
result
)
=>
{
return
res
.
status
(
200
).
send
(
result
);
})
.
catch
((
error
)
=>
{
console
.
log
(
error
);
return
res
.
status
(
500
).
json
({
error
});
});
};
export
default
{
create
,
getAll
,
get
,
deleteDoc
,
update
,
};
backend/src/routes/Location.ts
View file @
f0a6ca24
...
...
@@ -9,6 +9,7 @@ const router: Router = express.Router();
router
.
get
(
'/'
,
controller
.
getAll
(
model
));
router
.
post
(
'/'
,
controller
.
create
(
model
));
router
.
get
(
'/:id'
,
controller
.
get
(
model
));
router
.
put
(
'/:id'
,
controller
.
update
(
model
));
router
.
delete
(
'/:id'
,
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
...
...
backend/src/routes/category.ts
View file @
f0a6ca24
...
...
@@ -8,6 +8,8 @@ const router: Router = express.Router();
router
.
get
(
'/'
,
controller
.
getAll
(
model
));
router
.
post
(
'/'
,
controller
.
create
(
model
));
router
.
get
(
'/:id'
,
controller
.
get
(
model
));
router
.
put
(
'/:id'
,
controller
.
update
(
model
));
router
.
delete
(
'/:id'
,
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
const
id
=
req
.
params
.
id
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment