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-09-03 17:35:59 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0aaeee51ffae22e6606219ddd7ad32728597988f
0aaeee51
1 parent
a6948c55
Implement api/session/createproblem with self selecting problems
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
3 deletions
jaksimsamil-server/src/api/session/session.ctrl.js
jaksimsamil-server/src/api/session/session.ctrl.js
View file @
0aaeee5
const
Participation
=
require
(
"../../models/participation"
);
const
Session
=
require
(
"../../models/session"
);
const
Group
=
require
(
"../../models/group"
);
const
User
=
require
(
"../../models/user"
);
const
mongoose
=
require
(
"mongoose"
);
const
{
ObjectId
}
=
mongoose
.
Types
;
/* POST /api/session/createproblem/:how
{
problemList:[Number]
sessionId: ObjectId,
groupId: ObjectId,
problemList:[Number],
}
*/
exports
.
createProblem
=
async
(
ctx
)
=>
{
try
{
let
{
sessionId
,
groupId
,
problemList
}
=
ctx
.
request
.
body
;
if
(
typeof
(
sessionId
)
===
'string'
){
sessionId
=
new
ObjectId
(
sessionId
);
}
if
(
typeof
(
groupId
)
===
'string'
){
groupId
=
new
ObjectId
(
groupId
);
}
if
(
typeof
(
problemList
)
===
'string'
){
problemList
=
JSON
.
parse
(
problemList
);
}
const
participation
=
await
Participation
.
findOne
({
sessionId
:
sessionId
,
groupId
:
groupId
});
const
group
=
await
Group
.
findById
(
groupId
);
const
how
=
ctx
.
params
.
how
;
if
(
how
===
'self'
){
let
check
=
true
;
for
(
let
i
=
0
;
i
<
group
.
members
.
length
;
i
++
){
const
user
=
await
User
.
findById
(
group
.
members
[
i
]);
console
.
log
(
user
);
console
.
log
(
typeof
(
user
.
solvedBJ_date
.
solvedBJbyDATE
));
let
userProblemList
=
[];
for
(
let
key
in
user
.
solvedBJ_date
.
solvedBJbyDATE
){
userProblemList
.
push
(
user
.
solvedBJ_date
.
solvedBJbyDATE
[
key
]);
}
userProblemList
=
userProblemList
.
flat
().
map
(
elem
=>
elem
.
problem_number
);
for
(
let
j
=
0
;
j
<
problemList
.
length
;
j
++
){
if
(
userProblemList
.
includes
(
problemList
[
j
])){
check
=
false
;
break
;
}
}
}
if
(
!
check
){
ctx
.
throw
(
'그룹원이 이미 푼 문제는 등록할 수 없습니다.'
);
return
;
}
else
{
problemList
.
map
(
async
problemNum
=>
await
participation
.
addProblem
({
problemNum
:
problemNum
,
isSolved
:
false
}));
ctx
.
body
=
participation
.
serialize
();
}
}
else
if
(
how
===
'recommend'
){
//TODO
}
}
catch
(
e
){
...
...
Please
register
or
login
to post a comment