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
45ffbc06
Commit
45ffbc06
authored
Aug 05, 2015
by
陈家荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xiugai
parent
2758d153
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
80 deletions
+39
-80
forumThreadService.js
app/service/forumThreadService.js
+25
-80
forumUserService.js
app/service/forumUserService.js
+14
-0
No files found.
app/service/forumThreadService.js
View file @
45ffbc06
...
...
@@ -4,6 +4,7 @@ var ForumThread = mongoose.model('ForumThread');
var
ForumComment
=
mongoose
.
model
(
'ForumComment'
);
var
ForumShare
=
mongoose
.
model
(
'ForumShare'
);
var
forumUserService
=
require
(
'./forumUserService'
);
var
forumCommentService
=
require
(
'./forumCommentService'
);
var
async
=
require
(
'async'
);
...
...
@@ -972,43 +973,17 @@ exports.remove = function(array,val) {
};
function
getAllThreadByFidHelpAndNickName
(
user_ids
,
conditions
,
pageNo
,
pageSize
,
sort
,
callback
)
{
conditions
.
from
=
{
"$in"
:
user_ids
};
//获取数量
function
countAllByConditionsAndNickName
(
nickName
,
conditions
,
callback
)
{
ForumThread
.
find
(
conditions
).
populate
(
'from'
).
exec
(
function
(
err
,
results
){
countAllByFid
(
conditions
,
function
(
err
,
count
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
if
(
results
){
var
count
=
0
;
//匹配 nickName
for
(
var
i
in
results
){
if
(
results
[
i
].
from
){
if
(
results
[
i
].
from
.
nickName
){
var
flag
=
results
[
i
].
from
.
nickName
.
toString
().
indexOf
(
nickName
);
if
(
flag
>=
0
){
// 如果有
count
+=
1
;
}
}
}
}
callback
(
null
,
count
);
}
else
{
callback
(
null
,
0
);
}
}
});
}
function
getAllThreadByFidHelpAndNickName
(
nickName
,
conditions
,
pageNo
,
pageSize
,
sort
,
callback
)
{
countAllByConditionsAndNickName
(
nickName
,
conditions
,
function
(
err
,
count
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
var
sortBy
=
'-topTime -tag_topTime -created'
;
...
...
@@ -1025,61 +1000,17 @@ function getAllThreadByFidHelpAndNickName(nickName, conditions, pageNo, pageSize
sort
:
'-created'
},
select
:
'from to created content'
}).
sort
(
sortBy
).
exec
(
function
(
err
,
docs
)
{
}).
limit
(
limit
).
skip
(
skip
).
sort
(
sortBy
).
exec
(
function
(
err
,
docs
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
//匹配 nickName
var
new_threads
=
[];
for
(
var
i
in
docs
){
if
(
docs
[
i
].
from
){
if
(
docs
[
i
].
from
.
nickName
){
var
flag
=
docs
[
i
].
from
.
nickName
.
toString
().
indexOf
(
nickName
);
if
(
flag
>=
0
){
// 如果有
new_threads
.
push
(
docs
[
i
]);
}
}
}
}
var
return_threads
=
new_threads
.
slice
(
skip
,
skip
+
limit
);
var
obj
=
{};
obj
.
total
=
count
;
obj
.
pageNo
=
pageNo
;
obj
.
pageSize
=
pageSize
;
obj
.
items
=
return_threads
;
if
(
return_threads
&&
return_threads
.
length
>
0
)
{
var
asyncTasks
=
[];
return_threads
.
forEach
(
function
(
doc
)
{
// console.log(doc);
if
(
doc
.
type
===
1
||
doc
.
level
!==
1
)
{
//非照片墙或文章时获取评论
asyncTasks
.
push
(
function
(
callback
)
{
populateComment
(
doc
,
callback
);
});
}
else
{
asyncTasks
.
push
(
function
(
callback
)
{
getSubThreads
(
doc
,
null
,
callback
);
});
}
});
async
.
parallel
(
asyncTasks
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
null
,
null
);
}
else
{
obj
.
items
=
results
;
callback
(
null
,
obj
);
}
});
}
else
{
callback
(
null
,
obj
);
}
obj
.
items
=
docs
;
callback
(
null
,
obj
);
}
});
}
...
...
@@ -1088,5 +1019,19 @@ function getAllThreadByFidHelpAndNickName(nickName, conditions, pageNo, pageSize
//获取全部列表数据
exports
.
getAllThreadByFidAndNickName
=
function
(
nickName
,
conditions
,
pageNo
,
pageSize
,
sort
,
callback
)
{
getAllThreadByFidHelpAndNickName
(
nickName
,
conditions
,
pageNo
,
pageSize
,
sort
,
callback
);
};
\ No newline at end of file
//查询到用户
forumUserService
.
searchMembersByNickName
(
nickName
,
function
(
err
,
users
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
//查询对应用户的文章
var
user_ids
=
[];
for
(
var
i
in
users
){
user_ids
.
push
(
users
[
i
].
_id
);
}
getAllThreadByFidHelpAndNickName
(
user_ids
,
conditions
,
pageNo
,
pageSize
,
sort
,
callback
);
}
});
}
\ No newline at end of file
app/service/forumUserService.js
View file @
45ffbc06
...
...
@@ -165,3 +165,17 @@ exports.searchMembersAndLimitActions=function(pageNo, pageSize, q, callback){
callback
(
err
,
rsJson
);
});
};
//根据nickName查询用户
exports
.
searchMembersByNickName
=
function
(
nickName
,
callback
){
var
name
=
{
nickName
:
{
$regex
:
nickName
,
$options
:
'i'
}
};
ForumUser
.
find
(
name
).
exec
(
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
result
);
}
});
};
\ 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