Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
RIT_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박권수
2021-05-06 03:18:34 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
96a36f8c41227d67c0d496c53d09f8e8ed7a52c0
96a36f8c
1 parent
8bb8449a
db. models implemented
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
11 deletions
server/src/models/bottle.js
server/src/models/hub.js
server/src/models/user.js
server/src/models/bottle.js
View file @
96a36f8
const
mongoose
=
require
(
'mongoose'
);
const
Schema
=
mongoose
.
Schema
;
const
BottleSchema
=
new
Schema
({
bottleId
:
{
type
:
String
,
required
:
true
,
unique
:
true
},
balance
:
Number
,
recentOpen
:
Date
,
medicineId
:
Number
,
hubId
:
Number
})
module
.
exports
=
mongoose
.
model
(
'Bottle'
,
BottleSchema
);
\ No newline at end of file
...
...
server/src/models/hub.js
View file @
96a36f8
...
...
@@ -3,24 +3,28 @@ const mongoose = require('mongoose');
const
Schema
=
mongoose
.
Schema
;
const
HubSchema
=
new
Schema
({
hubId
:
{
type
:
Number
,
required
:
true
},
hubId
:
{
type
:
Number
,
required
:
true
,
unique
:
true
},
hosting
:
Object
,
userId
:
{
type
:
String
,
default
:
null
},
hosting
:
Object
});
HubSchema
.
methods
.
setHubHost
=
async
(
hosting
)
=>
{
HubSchema
.
statics
.
findByHubId
=
function
(
hubId
)
{
return
this
.
findOne
({
hubId
})
}
HubSchema
.
methods
.
setHubHost
=
function
(
hosting
)
{
this
.
hosting
=
hosting
;
}
HubSchema
.
methods
.
getHubHost
=
async
()
=>
{
HubSchema
.
methods
.
getHubHost
=
function
()
{
return
this
.
hosting
;
}
HubSchema
.
methods
.
setHub_UserId
=
async
(
userId
)
=>
{
HubSchema
.
methods
.
setHub_UserId
=
function
(
userId
)
{
this
.
userId
=
userId
;
}
HubSchema
.
methods
.
getHub_UserId
=
async
()
=>
{
HubSchema
.
methods
.
getHub_UserId
=
function
()
{
return
this
.
userId
;
}
...
...
server/src/models/user.js
View file @
96a36f8
...
...
@@ -5,25 +5,25 @@ const jwt = require('jsonwebtoken');
const
Schema
=
mongoose
.
Schema
;
const
UserSchema
=
new
Schema
({
userId
:
{
type
:
String
,
require
:
true
},
userId
:
{
type
:
String
,
require
:
true
,
unique
:
true
},
hashedPassword
:
{
type
:
String
,
default
:
null
}
})
UserSchema
.
methods
.
setPassword
=
async
(
password
)
=>
{
UserSchema
.
methods
.
setPassword
=
async
function
(
password
)
{
const
hash
=
await
bycrypt
(
password
,
10
);
this
.
hashedPassword
=
hash
;
}
UserSchema
.
methods
.
checkPassword
=
async
(
password
)
=>
{
UserSchema
.
methods
.
checkPassword
=
async
function
(
password
)
{
const
result
=
await
bycrypt
.
compare
(
password
,
this
.
hashedPassword
)
return
result
;
}
UserSchema
.
statics
.
findByUserId
=
async
(
userId
)
=>
{
UserSchema
.
statics
.
findByUserId
=
async
function
(
userId
)
{
return
this
.
findOne
({
userId
});
}
UserSchema
.
methods
.
generateToken
=
()
=>
{
UserSchema
.
methods
.
generateToken
=
function
()
{
const
token
=
jwt
.
sign
(
{
_id
:
this
.
_id
,
...
...
Please
register
or
login
to post a comment