Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-066
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
2022-066
2022-066
Commits
c0fbeb27
Commit
c0fbeb27
authored
Apr 23, 2022
by
Navodya Pasqual
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backend updated
parent
161b8850
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
7 additions
and
280 deletions
+7
-280
Backend/Node/server.js
Backend/Node/server.js
+1
-11
Backend/Node/src/controllers/controller.site.js
Backend/Node/src/controllers/controller.site.js
+0
-82
Backend/Node/src/controllers/controller.supplier.js
Backend/Node/src/controllers/controller.supplier.js
+0
-82
Backend/Node/src/modules/module.site.js
Backend/Node/src/modules/module.site.js
+0
-31
Backend/Node/src/modules/module.supplier.js
Backend/Node/src/modules/module.supplier.js
+0
-38
Backend/Node/src/routes/route.site.js
Backend/Node/src/routes/route.site.js
+0
-18
Backend/Node/src/routes/route.supplier.js
Backend/Node/src/routes/route.supplier.js
+0
-18
Backend/package-lock.json
Backend/package-lock.json
+6
-0
No files found.
Backend/Node/server.js
View file @
c0fbeb27
...
...
@@ -3,16 +3,11 @@ const mongoose = require('mongoose');
const
dotenv
=
require
(
'
dotenv
'
);
const
cors
=
require
(
'
cors
'
);
const
bodyParser
=
require
(
'
body-parser
'
);
const
SiteRoute
=
require
(
'
./src/routes/route.site
'
);
const
SupplierRoute
=
require
(
'
./src/routes/route.supplier
'
);
dotenv
.
config
();
const
app
=
express
();
app
.
use
(
cors
());
//
// parse requests of content-type - application/json
app
.
use
(
bodyParser
.
json
());
// parse requests of content-type - application/x-www-form-urlencoded
...
...
@@ -44,17 +39,12 @@ mongoose.connection.once('open', () => {
});
app
.
route
(
'
/
'
).
get
((
req
,
res
)
=>
{
res
.
send
(
'
CSSE Group
Project
'
);
res
.
send
(
'
Research
Project
'
);
});
require
(
'
./src/routes/auth.routes
'
)(
app
);
require
(
'
./src/routes/user.routes
'
)(
app
);
app
.
use
(
'
/site
'
,
SiteRoute
());
app
.
use
(
'
/supplier
'
,
SupplierRoute
());
app
.
listen
(
PORT
,
()
=>
{
console
.
log
(
'
######################################################
'
);
console
.
log
(
`Server is ON and running on PORT :
${
PORT
}
`
);
...
...
Backend/Node/src/controllers/controller.site.js
deleted
100644 → 0
View file @
161b8850
const
Site
=
require
(
'
../modules/module.site
'
);
const
{
next
}
=
require
(
"
lodash
"
);
const
createSite
=
(
req
,
res
)
=>
{
const
{
siteID
,
name
,
location
}
=
req
.
body
// validate fields
if
(
!
siteID
||
!
name
||
!
location
)
{
return
res
.
status
(
400
).
json
({
error
:
"
All fields are required
"
});
}
Site
.
create
({
siteID
,
name
,
location
},(
err
,
name
)
=>
{
if
(
err
)
{
return
res
.
status
(
400
).
json
({
error
:
'
Error Found
'
});
}
res
.
json
(
name
);
});
}
const
getAllSites
=
(
req
,
res
)
=>
{
let
order
=
req
.
query
.
order
?
req
.
query
.
order
:
'
asc
'
let
sortBy
=
req
.
query
.
sortBy
?
req
.
query
.
sortBy
:
'
_id
'
Site
.
find
()
.
sort
([[
sortBy
,
order
]])
.
exec
((
err
,
site
)
=>
{
if
(
err
)
{
return
res
.
status
(
400
).
json
({
error
:
'
No data Found
'
});
}
res
.
json
(
site
);
});
}
const
siteById
=
async
(
req
,
res
)
=>
{
Site
.
findById
(
req
.
params
.
id
,
(
error
,
data
)
=>
{
if
(
error
)
{
return
next
(
error
)
}
else
{
res
.
json
(
data
)
}
})
};
const
updateById
=
async
(
req
,
res
)
=>
{
const
{
slug
}
=
req
.
params
const
{
siteID
,
name
,
location
}
=
req
.
body
Site
.
findOneAndUpdate
({
slug
},
{
siteID
,
name
,
location
},
{
new
:
true
})
.
exec
((
err
,
site
)
=>
{
if
(
err
)
console
.
log
(
err
)
res
.
json
(
site
);
})
};
const
deleteById
=
async
(
req
,
res
)
=>
{
const
id
=
req
.
params
.
id
await
Site
.
findByIdAndRemove
(
id
).
exec
()
res
.
send
(
"
Deleted
"
);
};
const
countSites
=
(
req
,
res
)
=>
{
Site
.
count
({
},
function
(
err
,
result
)
{
if
(
err
)
{
res
.
send
(
err
);
}
else
{
res
.
json
(
result
);
}
});
};
module
.
exports
=
{
createSite
,
siteById
,
getAllSites
,
updateById
,
deleteById
,
countSites
}
\ No newline at end of file
Backend/Node/src/controllers/controller.supplier.js
deleted
100644 → 0
View file @
161b8850
const
Supplier
=
require
(
'
../modules/module.supplier
'
);
const
{
next
}
=
require
(
"
lodash
"
);
const
createSupplier
=
(
req
,
res
)
=>
{
const
{
supplierID
,
name
,
address
,
contactNo
}
=
req
.
body
// validate fields
if
(
!
supplierID
||
!
name
||
!
address
||
!
contactNo
)
{
return
res
.
status
(
400
).
json
({
error
:
"
All fields are required
"
});
}
Supplier
.
create
({
supplierID
,
name
,
address
,
contactNo
},(
err
,
name
)
=>
{
if
(
err
)
{
return
res
.
status
(
400
).
json
({
error
:
'
Error Found
'
});
}
res
.
json
(
name
);
});
}
const
getAllSuppliers
=
(
req
,
res
)
=>
{
let
order
=
req
.
query
.
order
?
req
.
query
.
order
:
'
asc
'
let
sortBy
=
req
.
query
.
sortBy
?
req
.
query
.
sortBy
:
'
_id
'
Supplier
.
find
()
.
sort
([[
sortBy
,
order
]])
.
exec
((
err
,
supplier
)
=>
{
if
(
err
)
{
return
res
.
status
(
400
).
json
({
error
:
'
No data Found
'
});
}
res
.
json
(
supplier
);
});
}
const
siteById
=
async
(
req
,
res
)
=>
{
Supplier
.
findById
(
req
.
params
.
id
,
(
error
,
data
)
=>
{
if
(
error
)
{
return
next
(
error
)
}
else
{
res
.
json
(
data
)
}
})
};
const
updateById
=
async
(
req
,
res
)
=>
{
const
{
slug
}
=
req
.
params
const
{
supplierID
,
name
,
address
,
contactNo
}
=
req
.
body
Supplier
.
findOneAndUpdate
({
slug
},
{
supplierID
,
name
,
address
,
contactNo
},
{
new
:
true
})
.
exec
((
err
,
supplier
)
=>
{
if
(
err
)
console
.
log
(
err
)
res
.
json
(
supplier
);
})
};
const
deleteById
=
async
(
req
,
res
)
=>
{
const
id
=
req
.
params
.
id
await
Supplier
.
findByIdAndRemove
(
id
).
exec
()
res
.
send
(
"
Deleted
"
);
};
const
countSuppliers
=
(
req
,
res
)
=>
{
Supplier
.
count
({
},
function
(
err
,
result
)
{
if
(
err
)
{
res
.
send
(
err
);
}
else
{
res
.
json
(
result
);
}
});
};
module
.
exports
=
{
createSupplier
,
siteById
,
getAllSuppliers
,
updateById
,
deleteById
,
countSuppliers
}
\ No newline at end of file
Backend/Node/src/modules/module.site.js
deleted
100644 → 0
View file @
161b8850
const
mongoose
=
require
(
'
mongoose
'
);
const
{
ObjectId
}
=
mongoose
.
Schema
;
const
SiteSchema
=
new
mongoose
.
Schema
(
{
siteID
:
{
type
:
String
,
required
:
true
,
trim
:
true
,
min
:
1
,
max
:
50
},
name
:
{
type
:
String
,
required
:
true
,
trim
:
true
,
min
:
1
,
max
:
50
},
location
:
{
type
:
String
,
required
:
true
,
trim
:
true
,
min
:
1
,
max
:
50
}
},
{
timestamps
:
true
}
);
module
.
exports
=
mongoose
.
model
(
'
sites
'
,
SiteSchema
);
\ No newline at end of file
Backend/Node/src/modules/module.supplier.js
deleted
100644 → 0
View file @
161b8850
const
mongoose
=
require
(
'
mongoose
'
);
const
{
ObjectId
}
=
mongoose
.
Schema
;
const
SupplierSchema
=
new
mongoose
.
Schema
(
{
supplierID
:
{
type
:
String
,
required
:
true
,
trim
:
true
,
min
:
1
,
max
:
50
},
name
:
{
type
:
String
,
required
:
true
,
trim
:
true
,
min
:
1
,
max
:
50
},
address
:
{
type
:
String
,
required
:
true
,
trim
:
true
,
min
:
1
,
max
:
50
},
contactNo
:
{
type
:
String
,
required
:
true
,
trim
:
true
,
min
:
1
,
max
:
50
}
},
{
timestamps
:
true
}
);
module
.
exports
=
mongoose
.
model
(
'
suppliers
'
,
SupplierSchema
);
\ No newline at end of file
Backend/Node/src/routes/route.site.js
deleted
100644 → 0
View file @
161b8850
const
express
=
require
(
'
express
'
);
const
router
=
express
.
Router
();
const
controller
=
require
(
'
../controllers/controller.site
'
);
module
.
exports
=
function
()
{
router
.
post
(
'
/create
'
,
controller
.
createSite
);
router
.
get
(
'
/
'
,
controller
.
getAllSites
);
router
.
get
(
'
/:id
'
,
controller
.
siteById
);
router
.
delete
(
'
/delete/:id
'
,
controller
.
deleteById
);
router
.
put
(
'
/update/:id
'
,
controller
.
updateById
);
router
.
get
(
'
/sites/count
'
,
controller
.
countSites
);
return
router
;
}
\ No newline at end of file
Backend/Node/src/routes/route.supplier.js
deleted
100644 → 0
View file @
161b8850
const
express
=
require
(
'
express
'
);
const
router
=
express
.
Router
();
const
controller
=
require
(
'
../controllers/controller.supplier
'
);
module
.
exports
=
function
()
{
router
.
post
(
'
/create
'
,
controller
.
createSupplier
);
router
.
get
(
'
/
'
,
controller
.
getAllSuppliers
);
router
.
get
(
'
/:id
'
,
controller
.
siteById
);
router
.
delete
(
'
/delete/:id
'
,
controller
.
deleteById
);
router
.
put
(
'
/update/:id
'
,
controller
.
updateById
);
router
.
get
(
'
/suppliers/count
'
,
controller
.
countSuppliers
);
return
router
;
}
\ No newline at end of file
Backend/package-lock.json
0 → 100644
View file @
c0fbeb27
{
"name"
:
"Backend"
,
"lockfileVersion"
:
2
,
"requires"
:
true
,
"packages"
:
{}
}
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