Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
exam_11_back
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
zarina
exam_11_back
Commits
d2e82b69
Commit
d2e82b69
authored
Jul 30, 2020
by
zarina
🌊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#4
, реализовала возможность удаления товара
parent
7aca4dca
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
82 additions
and
50 deletions
+82
-50
products.js
app/products.js
+22
-9
fixtures.js
fixtures.js
+58
-41
.gitignore
public/uploads/.gitignore
+2
-0
somePhoto.jpeg
public/uploads/somePhoto.jpeg
+0
-0
somePhoto1.jpeg
public/uploads/somePhoto1.jpeg
+0
-0
No files found.
app/products.js
View file @
d2e82b69
...
...
@@ -33,24 +33,37 @@ const createRouter = () => {
});
router
.
get
(
"/:id"
,
async
(
req
,
res
)
=>
{
const
product
=
await
Product
.
findById
(
req
.
params
.
id
).
populate
(
"category"
);
const
product
=
await
Product
.
findById
(
req
.
params
.
id
).
populate
(
'category author'
);
res
.
send
(
product
);
});
router
.
post
(
"/"
,
[
upload
.
single
(
"image"
),
auth
],
async
(
req
,
res
)
=>
{
const
product
=
new
Product
(
req
.
body
);
const
productData
=
req
.
body
;
productData
.
author
=
req
.
user
;
if
(
req
.
file
)
{
product
.
image
=
req
.
file
.
filename
;
productData
.
image
=
req
.
file
.
filename
;
}
else
{
productData
.
image
=
'ic-dialog.png'
;
}
const
product
=
new
Product
(
productData
);
try
{
res
.
send
(
await
product
.
save
());
}
catch
(
err
)
{
res
.
status
(
400
).
send
(
err
);
}
await
product
.
save
();
res
.
send
(
product
);
});
router
.
delete
(
"/:id"
,
async
(
req
,
res
)
=>
{
try
{
res
.
send
(
await
Product
.
findByIdAndRemove
(
req
.
params
.
id
));
}
catch
(
e
)
{
res
.
status
(
500
).
send
(
e
)}
router
.
delete
(
"/:id"
,
auth
,
async
(
req
,
res
)
=>
{
const
product
=
await
Product
.
findById
(
req
.
params
.
id
);
if
(
req
.
user
.
_id
.
toString
()
===
product
.
author
.
toString
())
{
await
Product
.
findByIdAndRemove
(
req
.
params
.
id
);
return
res
.
send
(
await
Product
.
find
());
}
else
{
return
res
.
sendStatus
(
403
);
}
});
...
...
fixtures.js
View file @
d2e82b69
...
...
@@ -17,7 +17,7 @@ db.once('open', async () => {
}
catch
(
e
)
{
console
.
log
(
'Collections were not present, skipping drop...'
);
}
const
[
user1
,
user2
]
=
await
User
.
create
({
const
[
user1
,
user2
]
=
await
User
.
create
({
username
:
'user'
,
password
:
'user'
,
displayName
:
'Some User'
,
...
...
@@ -29,12 +29,15 @@ db.once('open', async () => {
displayName
:
'Some User 2'
,
phone
:
'+324013248105'
,
token
:
''
});
}
);
const
[
category1
,
category2
]
=
await
Category
.
create
({
const
[
category1
,
category2
,
category3
]
=
await
Category
.
create
({
title
:
"some category"
,
},
{
},
{
title
:
"some category 2"
},
{
title
:
"some category 3"
});
await
Product
.
create
({
...
...
@@ -44,13 +47,27 @@ db.once('open', async () => {
description
:
'some description for some product'
,
image
:
'somePhoto.jpeg'
,
price
:
222
},
{
},
{
author
:
user1
.
_id
,
category
:
category2
.
_id
,
title
:
'some product 2'
,
description
:
'some description for some product 2'
,
image
:
'somePhoto1.jpeg'
,
price
:
154
price
:
154424
},
{
author
:
user1
.
_id
,
category
:
category2
.
_id
,
title
:
'some product 3'
,
description
:
'some description for some product 3'
,
image
:
'somePhoto1.jpeg'
,
price
:
154443
},{
author
:
user1
.
_id
,
category
:
category3
.
_id
,
title
:
'some product 4'
,
description
:
'some description for some product 4'
,
image
:
'somePhoto1.jpeg'
,
price
:
15453
});
db
.
close
();
...
...
public/uploads/.gitignore
View file @
d2e82b69
*
!.gitignore
!somePhoto1.jpeg
!somePhoto.jpeg
public/uploads/somePhoto.jpeg
0 → 100644
View file @
d2e82b69
1.11 KB
public/uploads/somePhoto1.jpeg
0 → 100644
View file @
d2e82b69
1.11 KB
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