Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
final-exam
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nawasan Wisitsingkhon
final-exam
Commits
80c40adf
Commit
80c40adf
authored
Oct 02, 2023
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove wishlsit by user
parent
92932730
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
2 deletions
+29
-2
WishlistController.js
app/controllers/WishlistController.js
+24
-1
user.js
app/routes/user.js
+1
-0
index.js
src/pages/index.js
+4
-1
No files found.
app/controllers/WishlistController.js
View file @
80c40adf
...
...
@@ -11,6 +11,7 @@ const WishlistController = {
const
wishlists
=
await
db
.
wishlist
.
findMany
({
where
:
{
user_id
:
Number
(
req
.
user
.
id
)
},
});
await
db
.
$disconnect
();
res
.
json
({
status
:
101
,
wishlists
});
}
catch
(
err
)
{
res
.
json
({
status
:
100
,
message
:
"found some error"
});
...
...
@@ -39,10 +40,32 @@ const WishlistController = {
});
res
.
json
({
status
:
201
,
message
:
"add wishlist success"
});
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
status
:
200
,
message
:
"found some error on server"
});
}
},
/**
*
* @param {Request} req
* @param {Response} res
*/
async
delete
(
req
,
res
)
{
try
{
const
{
id
}
=
req
.
query
;
if
(
!
id
)
throw
400
;
const
wishlist_find
=
await
db
.
wishlist
.
findFirst
({
where
:
{
product_id
:
Number
(
id
),
user_id
:
Number
(
req
.
user
.
id
),
},
});
if
(
!
wishlist_find
)
throw
400
;
await
db
.
wishlist
.
delete
({
where
:
{
id
:
wishlist_find
.
id
}})
await
db
.
$disconnect
();
res
.
json
({
status
:
401
,
message
:
"remove fav success"
});
}
catch
(
err
)
{
res
.
json
({
status
:
400
,
message
:
"remove fav failed with error"
});
}
},
};
export
default
WishlistController
;
app/routes/user.js
View file @
80c40adf
...
...
@@ -4,5 +4,6 @@ const UserRouter = express.Router();
UserRouter
.
get
(
"/wishlist"
,
WishlistController
.
index
);
UserRouter
.
post
(
"/wishlist"
,
WishlistController
.
create
);
UserRouter
.
delete
(
"/wishlist"
,
WishlistController
.
delete
);
export
default
UserRouter
;
src/pages/index.js
View file @
80c40adf
...
...
@@ -29,13 +29,16 @@ export default function Home() {
return
;
}
if
(
isRemove
)
{
let
response
=
await
axios
.
delete
(
`/api/u/wishlist?id=
${
id
}
`
,
{
headers
:
{
token
:
user
.
value
.
token
},
});
console
.
log
(
response
.
data
);
}
else
{
let
response
=
await
axios
.
post
(
"/api/u/wishlist"
,
{
id
},
{
headers
:
{
token
:
user
.
value
.
token
}
}
);
console
.
log
(
response
.
data
);
}
FetchWishlist
();
}
...
...
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