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
송용우
2020-08-25 21:59:08 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
b7662131a35ae9878f7cdc373739942472f5b0f6
b7662131
2 parents
0599acbe
f105bd7b
Merge branch 'develop' of
https://github.com/FacerAin/Jaksimsamil
into develop
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
93 additions
and
34 deletions
jaksimsamil-server/src/models/challenge.js
jaksimsamil-server/src/models/group.js
jaksimsamil-server/src/models/participation.js
jaksimsamil-server/src/models/problem.js
jaksimsamil-server/src/models/session.js
jaksimsamil-server/src/models/user.js
jaksimsamil-server/src/models/challenge.js
View file @
b766213
...
...
@@ -2,47 +2,48 @@ const mongoose = require("mongoose");
const
{
Schema
}
=
mongoose
;
const
ChallengeSchema
=
new
Schema
(
{
challengeName
:
{
type
:
String
,
required
:
true
},
startDate
:
{
type
:
Object
,
required
:
true
},
endDate
:
{
type
:
Object
,
required
:
true
},
durationPerSession
:
{
type
:
String
,
required
:
true
},
// '1d' means one day per session, '2w' means 2 weeks per session, '3m' means 3 months per session.
goalPerSession
:
{
type
:
Number
,
required
:
true
},
// number of problems for one session
isOpen
:
{
type
:
Boolean
},
},
{
collection
:
"challenge"
,
}
);
ChallengeSchema
.
statics
.
findByChallengeName
=
function
(
challengeName
)
{
return
this
.
findOne
({
challengeName
:
challengeName
});
};
ChallengeSchema
.
methods
.
getChallengeName
=
function
()
{
const
ChallengeSchema
=
new
Schema
({
challengeName
:
{
type
:
String
,
required
:
true
},
startDate
:
{
type
:
Object
,
required
:
true
},
endDate
:
{
type
:
Object
,
required
:
true
},
durationPerSession
:
{
type
:
String
,
required
:
true
},
// '1d' means one day per session, '2w' means 2 weeks per session, '3m' means 3 months per session.
goalPerSession
:
{
type
:
Number
,
required
:
true
},
// number of problems for one session
status
:
{
type
:
String
}
},{
collection
:
'challenge'
});
ChallengeSchema
.
statics
.
findByChallengeName
=
function
(
challengeName
){
return
this
.
findOne
({
challengeName
:
challengeName
});
}
ChallengeSchema
.
methods
.
getChallengeName
=
function
(){
return
this
.
challengeName
;
}
;
}
ChallengeSchema
.
methods
.
getStartDate
=
function
()
{
ChallengeSchema
.
methods
.
getStartDate
=
function
()
{
return
this
.
startDate
;
}
;
}
ChallengeSchema
.
methods
.
getEndDate
=
function
()
{
ChallengeSchema
.
methods
.
getEndDate
=
function
()
{
return
this
.
endDate
;
}
;
}
ChallengeSchema
.
method
s
.
getDurationPerSession
=
function
()
{
ChallengeSchema
.
method
.
getDurationPerSession
=
function
()
{
return
this
.
durationPerSession
;
}
;
}
ChallengeSchema
.
methods
.
getGoalPerSession
=
function
()
{
ChallengeSchema
.
methods
.
getGoalPerSession
=
function
()
{
return
this
.
goalPerSession
;
}
;
}
ChallengeSchema
.
methods
.
serialize
=
function
()
{
ChallengeSchema
.
methods
.
getStatus
=
function
(){
return
this
.
status
;
}
ChallengeSchema
.
methods
.
serialize
=
function
(){
return
this
.
toJSON
();
}
;
}
const
Challenge
=
mongoose
.
model
(
"Challenge"
,
ChallengeSchema
);
const
Challenge
=
mongoose
.
model
(
'Challenge'
,
ChallengeSchema
);
module
.
exports
=
Challenge
;
\ No newline at end of file
...
...
jaksimsamil-server/src/models/group.js
View file @
b766213
...
...
@@ -8,5 +8,18 @@ const GroupSchema = new Schema({
collection
:
'group'
});
GroupSchema
.
methods
.
addGroupMemeber
=
function
(
user
){
this
.
members
.
push
(
user
.
_id
);
return
this
.
save
();
}
GroupSchema
.
methods
.
getMembers
=
function
(){
return
this
.
members
;
}
GroupSchema
.
methods
.
serialize
=
function
(){
return
this
.
toJSON
();
}
const
Group
=
mongoose
.
model
(
'Group'
,
GroupSchema
);
module
.
exports
=
Group
;
\ No newline at end of file
...
...
jaksimsamil-server/src/models/participation.js
View file @
b766213
...
...
@@ -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
});
}
ParticipationSchema
.
statics
.
findByGroupId
=
function
(
group
){
return
this
.
find
({
groupId
:
group
.
_id
});
}
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/problem.js
View file @
b766213
...
...
@@ -9,7 +9,7 @@ const ProblemSchema=new Schema({
sumbitNum
:
{
type
:
Number
,
required
:
true
},
correctNum
:
{
type
:
Number
,
required
:
true
},
count
:
{
type
:
Number
},
category
:
{
type
:[
String
]}
category
:
[{
type
:
String
}],
},{
collection
:
'problem'
});
...
...
jaksimsamil-server/src/models/session.js
View file @
b766213
...
...
@@ -6,10 +6,30 @@ const SessionSchema = new Schema({
challengeId
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'Challenge'
},
sessionStartDate
:
{
type
:
Object
},
sessionEndDate
:
{
type
:
Object
},
isOpen
:
{
type
:
Boolean
}
status
:
{
type
:
String
}
},{
collection
:
'session'
});
SessionSchema
.
statics
.
findByChallengeId
=
function
(
challenge
){
return
this
.
find
({
challengeId
:
challenge
.
_id
});
}
SessionSchema
.
methods
.
getSessionStartDate
=
function
(){
return
this
.
sessionStartDate
;
}
SessionSchema
.
methods
.
getSessionEndDate
=
function
(){
return
this
.
sessionEndDate
;
}
SessionSchema
.
methods
.
getStatus
=
function
(){
return
this
.
status
;
}
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 @
b766213
...
...
@@ -21,6 +21,11 @@ UserSchema.statics.findByUsername = function (username) {
return
this
.
findOne
({
username
});
};
UserSchema
.
methods
.
addFriend
=
function
(
friend
){
this
.
friendList
.
push
(
friend
.
_id
);
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