Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
back
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
Container registry
Model registry
Operate
Environments
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
csb
back
Commits
4f5accfb
Commit
4f5accfb
authored
8 years ago
by
Nicolas Fley
Browse files
Options
Downloads
Patches
Plain Diff
api fixed, now working (without auth)
parent
8c12a27a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app.js
+1
-1
1 addition, 1 deletion
app.js
models/item.model.js
+5
-5
5 additions, 5 deletions
models/item.model.js
routes/item.route.js
+31
-14
31 additions, 14 deletions
routes/item.route.js
with
37 additions
and
20 deletions
app.js
+
1
−
1
View file @
4f5accfb
This diff is collapsed.
Click to expand it.
models/item.model.js
+
5
−
5
View file @
4f5accfb
...
...
@@ -18,7 +18,7 @@ var Items = sequelize.define('Items', {
tableItem
:
'
Items
'
,
});
sequelize
.
sync
().
then
(()
=>
{
sequelize
.
sync
(
{
force
:
true
}
).
then
(()
=>
{
Items
.
create
({
description
:
'
Slip semi-propre
'
,
price
:
4
,
...
...
@@ -40,7 +40,7 @@ function getItemsByDate(page, step) {
var
offset
=
(
page
*
step
);
return
Items
.
findAll
({
offset
:
offset
,
limit
:
step
,
limit
:
offset
+
step
,
order
:
[[
'
createdAt
'
,
'
DESC
'
]]
});
}
...
...
@@ -49,7 +49,7 @@ function getItemsByUserId(id, page, step){
var
offset
=
(
page
*
step
);
return
Items
.
findAll
({
offset
:
offset
,
limit
:
step
,
limit
:
offset
+
step
,
where
:
{
userId
:
id
}
});
}
...
...
@@ -58,7 +58,7 @@ function getItemsByDescription(description, page, step) {
var
offset
=
(
page
*
step
);
return
Items
.
findAll
({
offset
:
offset
,
limit
:
step
,
limit
:
offset
+
step
,
where
:
{
description
:
{
$like
:
`%
${
description
}
%`
}
}
});
}
...
...
This diff is collapsed.
Click to expand it.
routes/item.route.js
+
31
−
14
View file @
4f5accfb
var
express
=
require
(
'
express
'
);
var
itemModel
=
require
(
'
../models/item.model
'
);
var
router
=
express
.
Router
();
const
express
=
require
(
'
express
'
);
const
itemModel
=
require
(
'
../models/item.model
'
);
const
router
=
express
.
Router
();
router
.
get
(
'
/:id
'
,
function
(
req
,
res
)
{
var
id
=
parseInt
(
req
.
params
.
id
);
const
DEFAULT_PAGE
=
0
;
const
DEFAULT_STEP
=
10
;
router
.
get
(
'
/byId/:id
'
,
function
(
req
,
res
)
{
let
id
=
parseInt
(
req
.
params
.
id
);
itemModel
.
getItem
(
id
).
then
(
out
=>
res
.
json
(
out
));
});
router
.
get
(
'
/date
'
,
function
(
req
,
res
)
{
var
page
=
parseInt
(
req
.
params
.
page
);
var
step
=
parseInt
(
req
.
params
.
step
);
console
.
log
(
req
.
query
)
let
page
=
parseInt
(
req
.
query
.
page
);
let
step
=
parseInt
(
req
.
query
.
step
);
if
(
isNaN
(
page
))
page
=
DEFAULT_PAGE
;
if
(
isNaN
(
step
))
step
=
DEFAULT_STEP
;
itemModel
.
getItemsByDate
(
page
,
step
).
then
(
out
=>
res
.
json
(
out
));
});
router
.
get
(
'
/userId
'
,
function
(
req
,
res
)
{
var
userId
=
parseInt
(
req
.
params
.
userId
);
var
page
=
parseInt
(
req
.
params
.
page
);
var
step
=
parseInt
(
req
.
params
.
step
);
console
.
log
(
req
.
query
)
let
userId
=
parseInt
(
req
.
query
.
uId
);
let
page
=
parseInt
(
req
.
query
.
page
);
let
step
=
parseInt
(
req
.
query
.
step
);
if
(
isNaN
(
page
))
page
=
DEFAULT_PAGE
;
if
(
isNaN
(
step
))
step
=
DEFAULT_STEP
;
itemModel
.
getItemsByUserId
(
userId
,
page
,
step
).
then
(
out
=>
res
.
json
(
out
));
});
router
.
get
(
'
/description
'
,
function
(
req
,
res
)
{
var
page
=
parseInt
(
req
.
params
.
page
);
var
step
=
parseInt
(
req
.
params
.
step
);
itemModel
.
getItemsByDescription
(
req
.
params
.
description
,
page
,
step
).
then
(
out
=>
res
.
json
(
out
));
let
page
=
parseInt
(
req
.
query
.
page
);
let
step
=
parseInt
(
req
.
query
.
step
);
if
(
isNaN
(
page
))
page
=
DEFAULT_PAGE
;
if
(
isNaN
(
step
))
step
=
DEFAULT_STEP
;
itemModel
.
getItemsByDescription
(
req
.
query
.
desc
,
page
,
step
).
then
(
out
=>
res
.
json
(
out
));
});
router
.
post
(
'
/
'
,
function
(
req
,
res
)
{
...
...
@@ -32,7 +49,7 @@ router.post('/', function(req, res) {
});
router
.
delete
(
'
/:id
'
,
function
(
req
,
res
)
{
var
id
=
parseInt
(
req
.
params
.
id
);
let
id
=
parseInt
(
req
.
params
.
id
);
itemModel
.
deleteItem
(
id
).
then
(
out
=>
res
.
json
(
out
.
dataValues
))
.
catch
(()
=>
res
.
json
({
error
:
'
User does not exist
'
}));
});
...
...
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