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-27 17:49:24 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ae933b0735609a644797aade19c12b41d5ac3a46
ae933b07
1 parent
eb980f4a
Add routings and Fix errors
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
7 deletions
jaksimsamil-server/src/api/challenge/challege.ctrl.js
jaksimsamil-server/src/api/challenge/index.js
jaksimsamil-server/src/api/challenge/challege.ctrl.js
View file @
ae933b0
...
...
@@ -49,7 +49,7 @@ exports.addChallenge = async (ctx) => {
ctx
.
body
=
result
.
error
;
return
;
}
cons
t
{
le
t
{
challengeName
,
startDate
,
endDate
,
...
...
@@ -77,14 +77,24 @@ exports.addChallenge = async (ctx) => {
const
newChallenge
=
await
Challenge
.
findByChallengeName
(
challengeName
);
const
newChallenge_id
=
newChallenge
.
_id
;
const
timeStep
=
Number
(
durationPerSession
.
slice
(
0
,
-
1
))
for
(
let
s_date
=
startDate
,
e_date
=
s_date
;
s_date
<
endDate
;){
if
(
typeof
(
startDate
)
==
'string'
){
startDate
=
new
Date
(
startDate
);
}
if
(
typeof
(
endDate
)
==
'string'
){
endDate
=
new
Date
(
endDate
);
}
for
(
let
s_date
=
new
Date
(
startDate
);
s_date
<
endDate
;){
let
e_date
=
new
Date
(
s_date
);
if
(
durationPerSession
[
durationPerSession
.
length
-
1
]
===
'd'
){
console
.
log
(
'day'
);
e_date
.
setDate
(
s_date
.
getDate
()
+
timeStep
);
}
else
if
(
durationPerSession
[
durationPerSession
.
length
-
1
]
===
'w'
){
console
.
log
(
'week'
);
e_date
.
setDate
(
s_date
.
getDate
()
+
timeStep
*
7
);
}
else
if
(
durationPerSession
[
durationPerSession
.
length
-
1
]
===
'm'
){
console
.
log
(
'month'
);
e_date
.
setMonth
(
s_date
.
getMonth
()
+
timeStep
);
}
e_date
.
setMinutes
(
e_date
.
getMinutes
()
-
1
);
...
...
@@ -101,6 +111,7 @@ exports.addChallenge = async (ctx) => {
else
{
status
=
"end"
;
}
console
.
log
(
`start:
${
s_date
}
\nend:
${
e_date
}
`
);
const
session
=
new
Session
({
challengeId
:
newChallenge_id
,
sessionStartDate
:
s_date
,
...
...
@@ -108,10 +119,10 @@ exports.addChallenge = async (ctx) => {
status
:
status
,
});
await
session
.
save
();
s_date
=
e_date
;
s_date
=
new
Date
(
e_date
)
;
s_date
.
setMinutes
(
s_date
.
getMinutes
()
+
1
);
}
ctx
.
body
=
challenge
()
;
ctx
.
body
=
challenge
;
}
catch
(
e
)
{
ctx
.
throw
(
500
,
e
);
}
...
...
@@ -123,7 +134,7 @@ query string status can be in ['all','enrolled','progress','end']
*/
exports
.
list
=
async
(
ctx
)
=>
{
try
{
const
status
=
ctx
.
q
s
.
status
;
const
status
=
ctx
.
q
uery
.
status
;
if
(
status
!==
'all'
){
const
challenges
=
await
Challenge
.
find
({
status
:
status
}).
select
(
'-_id'
);
ctx
.
body
=
challenges
;
...
...
@@ -151,7 +162,8 @@ exports.participate=async (ctx)=>{
TODO: access token validation,
recommend:get username from access_token
*/
const
{
username
,
challengeName
}
=
ctx
.
body
;
console
.
log
(
ctx
.
request
.
body
);
const
{
username
,
challengeName
}
=
ctx
.
request
.
body
;
const
challenge
=
await
Challenge
.
findByChallengeName
(
challengeName
);
const
challenge_id
=
challenge
.
_id
;
const
user
=
await
User
.
findByUsername
(
username
);
...
...
@@ -159,9 +171,25 @@ exports.participate=async (ctx)=>{
const
newGroup
=
new
Group
({
members
:[
user_id
],
});
newGroup
.
save
();
let
newGroup_id
=
""
await
newGroup
.
save
(
async
(
err
,
product
)
=>
{
if
(
err
){
throw
err
;
}
newGroup_id
=
product
.
_id
;
const
sessions
=
await
Session
.
findByChallengeId
(
challenge_id
);
sessions
.
forEach
(
async
(
elem
)
=>
{
const
newParticipation
=
new
Participation
({
sessionId
:
elem
.
_id
,
groupId
:
newGroup_id
,
problems
:[],
});
await
newParticipation
.
save
();
});
});
}
catch
(
e
){
console
.
error
(
e
);
ctx
.
throw
(
500
,
e
);
}
};
\ No newline at end of file
...
...
jaksimsamil-server/src/api/challenge/index.js
View file @
ae933b0
...
...
@@ -4,5 +4,7 @@ const challengeCtrl = require('./challege.ctrl');
challenge
.
post
(
"/getchallenge"
,
challengeCtrl
.
getChallenge
);
challenge
.
post
(
"/addchallenge"
,
challengeCtrl
.
addChallenge
);
challenge
.
get
(
"/list"
,
challengeCtrl
.
list
);
challenge
.
post
(
"/participate"
,
challengeCtrl
.
participate
);
module
.
exports
=
challenge
;
\ No newline at end of file
...
...
Please
register
or
login
to post a comment