Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pisns-forum-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
scrmGroup
pisns-forum-api
Commits
40f56068
Commit
40f56068
authored
Aug 28, 2015
by
刘文胜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1111
parent
39c167aa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
+92
-0
forumCommentService.js
app/service/forumCommentService.js
+92
-0
No files found.
app/service/forumCommentService.js
View file @
40f56068
...
...
@@ -300,4 +300,96 @@ exports.getPopulateCommentById=function(cid,callback){
callback
(
null
,
c
);
}
});
};
//我的评论
var
countMyComment
=
function
(
conditions
,
callback
)
{
ForumComment
.
find
(
conditions
)
.
count
(
conditions
,
function
(
err
,
count
)
{
if
(
err
){
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
count
);
}
});
};
function
populateParentComment
(
doc
,
callback
){
if
(
doc
&&
doc
.
_id
&&
doc
.
level
===
2
)
{
ForumComment
.
findOne
({
comments
:
{
$elemMatch
:
doc
.
_id
},
status
:
1
}).
exec
(
function
(
err
,
c
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
null
,
null
);
}
else
{
if
(
c
){
callback
(
null
,
c
);
}
else
{
callback
(
null
);
}
}
});
}
else
{
callback
(
null
,
null
);
}
}
//我的评论
exports
.
getMyComment
=
function
(
conditions
,
pageNo
,
pageSize
,
callback
){
countMyComment
(
conditions
,
function
(
err
,
count
){
if
(
err
){
callback
(
err
);
}
else
{
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
ForumComment
.
find
(
conditions
)
.
populate
({
path
:
'thread'
,
select
:
'_id content title type level tag'
}).
populate
({
path
:
'from to'
,
select
:
'uid nickName icon'
}).
limit
(
limit
).
skip
(
skip
).
sort
(
'-created'
).
exec
(
function
(
err
,
docs
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
var
obj
=
{};
obj
.
total
=
count
;
obj
.
pageNo
=
pageNo
;
obj
.
pageSize
=
pageSize
;
obj
.
items
=
docs
;
if
(
docs
&&
docs
.
length
>
0
)
{
var
asyncTasks
=
[];
docs
.
forEach
(
function
(
doc
){
asyncTasks
.
push
(
function
(
callback
)
{
populateParentComment
(
doc
,
function
(
err
,
c
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
var
newobj
=
doc
.
toObject
();
newobj
.
parent
=
c
;
delete
newobj
.
comments
;
callback
(
null
,
newobj
);
}
});
});
});
async
.
parallel
(
asyncTasks
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
null
,
null
);
}
else
{
obj
.
items
=
results
;
callback
(
null
,
obj
);
}
});
}
else
{
callback
(
null
,
obj
);
}
}
});
}
});
};
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment