Toggle navigation
Toggle navigation
This project
Loading...
Sign in
송용우
/
oss-Jaksimsamil
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
JJuOn
2020-08-25 15:52:47 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
dff7309c1caca08528e2d5d6b8caa32b0e359ccc
dff7309c
1 parent
ce195302
Add statics and methods to models
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
1 deletions
jaksimsamil-server/src/models/group.js
jaksimsamil-server/src/models/participation.js
jaksimsamil-server/src/models/session.js
jaksimsamil-server/src/models/user.js
jaksimsamil-server/src/models/group.js
View file @
dff7309
...
...
@@ -8,5 +8,10 @@ const GroupSchema = new Schema({
collection
:
'group'
});
GroupSchema
.
methods
.
addGroupMemeber
=
function
(
user
){
this
.
members
.
push
({
$oid
:
user
.
_id
.
$oid
});
return
this
.
save
();
}
const
Group
=
mongoose
.
model
(
'Group'
,
GroupSchema
);
module
.
exports
=
Group
;
\ No newline at end of file
...
...
jaksimsamil-server/src/models/participation.js
View file @
dff7309
...
...
@@ -2,12 +2,32 @@ const mongoose = require("mongoose");
const
{
Schema
}
=
mongoose
;
const
SelectedProblemSchema
=
new
Schema
({
problemNum
:
{
type
:
Number
,
required
:
true
},
isSolved
:
{
type
:
Boolean
,
default
:
false
},
},{
_id
:
false
});
const
ParticipationSchema
=
new
Schema
({
sessionId
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'Session'
},
groupId
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'Group'
}
groupId
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'Group'
},
problems
:
[{
type
:
SelectedProblemSchema
}]
},{
collection
:
'particiaption'
});
ParticipationSchema
.
statics
.
findBySessionId
=
function
(
session
){
return
this
.
find
({
sessionId
:
session
.
_id
.
$oid
});
}
ParticipationSchema
.
statics
.
findByGroupId
=
function
(
group
){
return
this
.
find
({
groupId
:
group
.
_id
.
$oid
});
}
ParticipationSchema
.
methods
.
addProblem
=
function
(
problem
){
this
.
problems
.
push
({
problemNum
:
problem
.
problemNum
,
isSolved
:
problem
.
isSolved
});
}
const
Participation
=
mongoose
.
model
(
'Participation'
,
ParticipationSchema
);
module
.
exports
=
Participation
;
\ No newline at end of file
...
...
jaksimsamil-server/src/models/session.js
View file @
dff7309
...
...
@@ -11,5 +11,25 @@ const SessionSchema = new Schema({
collection
:
'session'
});
SessionSchema
.
statics
.
findByChallengeId
=
function
(
challenge
){
return
this
.
find
({
challengeId
:
challenge
.
_id
.
$oid
});
}
SessionSchema
.
methods
.
getSessionStartDate
=
function
(){
return
this
.
sessionStartDate
;
}
SessionSchema
.
methods
.
getSessionEndDate
=
function
(){
return
this
.
sessionEndDate
;
}
SessionSchema
.
methods
.
getIsOpen
=
function
(){
return
this
.
isOpen
;
}
SessionSchema
.
methods
.
serialize
=
function
(){
return
this
.
toJSON
();
}
const
Session
=
mongoose
.
model
(
'Session'
,
SessionSchema
);
module
.
exports
=
Session
;
\ No newline at end of file
...
...
jaksimsamil-server/src/models/user.js
View file @
dff7309
...
...
@@ -21,6 +21,11 @@ UserSchema.statics.findByUsername = function (username) {
return
this
.
findOne
({
username
});
};
UserSchema
.
methods
.
addFriend
=
function
(
friend
){
this
.
friendList
.
push
({
$oid
:
friend
.
_id
.
$oid
});
return
this
.
save
();
}
UserSchema
.
methods
.
setPassword
=
async
function
(
password
)
{
const
hash
=
await
bcrypt
.
hash
(
password
,
10
);
this
.
hashedPassword
=
hash
;
...
...
Please
register
or
login
to post a comment