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
dc86d020
Commit
dc86d020
authored
Feb 09, 2015
by
张淼
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
1cad2611
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
946 additions
and
0 deletions
+946
-0
forumFavorite.js
app/controllers/mobile/forumFavorite.js
+61
-0
forumGroup.js
app/controllers/mobile/forumGroup.js
+77
-0
forumInfo.js
app/controllers/mobile/forumInfo.js
+107
-0
forumRole.js
app/controllers/mobile/forumRole.js
+83
-0
forumRolePermission.js
app/controllers/mobile/forumRolePermission.js
+48
-0
forumTag.js
app/controllers/mobile/forumTag.js
+135
-0
forumThread.js
app/controllers/mobile/forumThread.js
+435
-0
No files found.
app/controllers/mobile/forumFavorite.js
0 → 100644
View file @
dc86d020
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
forumFavoriteService
=
require
(
'../../service/forumFavoriteService'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
};
//文章收藏
router
.
post
(
'/favorite/create'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{};
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
forumFavoriteService
.
createFavorite
(
req
.
body
,
function
(
err
,
entity
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
{
'id'
:
entity
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
});
//删除收藏
router
.
post
(
'/favorite/:fid/delete'
,
function
(
req
,
res
,
next
)
{
var
fid
=
req
.
params
.
fid
;
if
(
fid
){
forumFavoriteService
.
deleteFavoriteById
(
fid
,
function
(
err
,
thread
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//获取当前用户的收藏列表
router
.
get
(
'/favorite/list'
,
function
(
req
,
res
,
next
)
{
var
user
=
req
.
query
.
user
;
if
(
fid
){
forumThreadService
.
getAll
(
req
.
session
.
user
.
ent_code
,
user
,
pageNo
,
pageSize
,
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
app/controllers/mobile/forumGroup.js
0 → 100644
View file @
dc86d020
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
ForumGroup
=
mongoose
.
model
(
'ForumGroup'
);
var
ForumInfo
=
mongoose
.
model
(
'ForumInfo'
);
var
forumGroupService
=
require
(
'../../service/forumGroupService'
);
var
forumInfoService
=
require
(
'../../service/forumInfoService'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
};
//新增论坛组
router
.
post
(
'/group/create'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{};
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
forumGroupService
.
createGroup
(
req
.
body
,
function
(
err
,
group
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
{
'id'
:
group
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
});
//获取目标论坛组信息
router
.
get
(
'/group/:gid/info'
,
function
(
req
,
res
,
next
)
{
var
gid
=
req
.
params
.
gid
||
null
;
var
rs
=
{};
if
(
gid
)
{
forumGroupService
.
getGroupById
(
gid
,
function
(
err
,
group
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
group
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
/**
* 获取板块列表
* @param {[type]} req [description]
* @param {[type]} res [description]
* @param {[type]} next) { var pageNo [description]
* @return {[type]} [description]
*/
router
.
get
(
'/group/:gid/forumInfos'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
gid
=
req
.
params
.
gid
;
if
(
gid
){
forumInfoService
.
getAll
(
req
.
session
.
user
.
ent_code
,
gid
,
pageNo
,
pageSize
,
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
\ No newline at end of file
app/controllers/mobile/forumInfo.js
0 → 100644
View file @
dc86d020
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
ForumInfo
=
mongoose
.
model
(
'ForumInfo'
);
var
forumInfoService
=
require
(
'../../service/forumInfoService'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
};
//新增论坛板块
router
.
post
(
'/info/create'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{};
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
forumInfoService
.
createInfo
(
req
.
body
,
function
(
err
,
info
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
{
'id'
:
info
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
});
//获取目标论坛板块
router
.
get
(
'/info/:fid/get'
,
function
(
req
,
res
,
next
)
{
var
fid
=
req
.
params
.
fid
||
null
;
var
rs
=
{};
if
(
fid
)
{
forumInfoService
.
getInfoById
(
fid
,
function
(
err
,
info
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
info
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//更新目标论坛板块
router
.
post
(
'/info/:fid/update'
,
function
(
req
,
res
,
next
)
{
var
fid
=
req
.
params
.
fid
;
if
(
fid
){
forumInfoService
.
updateInfoById
(
fid
,
req
.
body
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//删除目标论坛板块
router
.
post
(
'/info/:fid/delete'
,
function
(
req
,
res
,
next
)
{
var
fid
=
req
.
params
.
fid
;
if
(
fid
){
forumInfoService
.
deleteInfoById
(
fid
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
/**
* [description]
* @param {[type]}
* @param {[type]}
* @param {[type]}
* @return {[type]}
*/
router
.
get
(
'/info/:fid/threads'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
fid
=
req
.
params
.
fid
;
if
(
fid
){
forumThreadService
.
getAll
(
req
.
session
.
user
.
ent_code
,
fid
,
pageNo
,
pageSize
,
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
app/controllers/mobile/forumRole.js
0 → 100644
View file @
dc86d020
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
ForumRole
=
mongoose
.
model
(
'ForumRole'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
};
//新增论坛角色
router
.
post
(
'/role/create'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{};
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
var
forum
=
new
ForumRole
(
req
.
body
);
forum
.
save
(
function
(
err
,
forum
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
forum
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
});
//删除论坛角色
router
.
post
(
'/role/:rid/delete'
,
function
(
req
,
res
,
next
)
{
var
rid
=
req
.
params
.
rid
;
ForumRole
.
remove
({
_id
:
rid
},
function
(
err
,
result
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
});
//更新论坛角色
router
.
post
(
'/role/:rid/update'
,
function
(
req
,
res
,
next
)
{
var
rid
=
req
.
params
.
rid
;
ForumRole
.
update
({
_id
:
rid
},
req
.
body
,
null
,
function
(
err
,
result
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
});
//获取角色列表
router
.
get
(
'/role/list'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
rs
=
{};
ForumRole
.
count
({
ent_code
:
req
.
session
.
user
.
ent_code
,
status
:
1
},
function
(
err
,
count
)
{
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
ForumRole
.
find
({
ent_code
:
req
.
session
.
user
.
ent_code
,
status
:
1
},
null
,
{
skip
:
skip
,
limit
:
limit
},
function
(
err
,
docs
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
total
=
count
;
rs
.
pageNo
=
pageNo
;
rs
.
pageSize
=
pageSize
;
rs
.
items
=
docs
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
});
app/controllers/mobile/forumRolePermission.js
0 → 100644
View file @
dc86d020
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
ForumRolePermission
=
mongoose
.
model
(
'ForumRolePermission'
);
var
forumRolePermissionService
=
require
(
'../../service/forumRolePermissionService'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
};
//新增角色权限
router
.
post
(
'/rolePermiss/create'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{};
var
form
=
{
ent_code
:
req
.
session
.
user
.
ent_code
};
var
group
=
new
ForumRolePermission
(
_
.
assign
(
form
,
req
.
body
));
group
.
save
(
function
(
err
,
group
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
{
'id'
:
group
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
});
//获取角色权限列表
router
.
get
(
'/rolePermiss/list'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
forumRolePermissionService
.
getAllRolePermission
(
req
.
session
.
user
.
ent_code
,
pageNo
,
pageSize
,
function
(
err
,
docs
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
docs
,
returnCode
.
SUCCESS
));
}
});
});
app/controllers/mobile/forumTag.js
0 → 100644
View file @
dc86d020
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
ForumTag
=
mongoose
.
model
(
'ForumTag'
);
var
ForumThread
=
mongoose
.
model
(
'ForumThread'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
};
//新增论坛标签
router
.
post
(
'/tag/create'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{};
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
var
forum
=
new
ForumTag
(
req
.
body
);
forum
.
save
(
function
(
err
,
forum
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
{
'id'
:
forum
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
});
//删除论坛标签
router
.
post
(
'/tag/:tid/delete'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
ForumTag
.
remove
({
_id
:
tid
},
function
(
err
,
result
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
});
//更新论坛标签
router
.
post
(
'/tag/:tid/update'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
ForumTag
.
update
({
_id
:
tid
},
req
.
body
,
null
,
function
(
err
,
result
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
});
//获取论坛标签
router
.
get
(
'/tag/:tid/get'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
rs
=
{};
if
(
fid
)
{
ForumTag
.
findById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
thread
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//查询所有标签
router
.
get
(
'/tag/list'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
rs
=
{};
var
group
=
new
ForumGroup
(
req
.
body
);
ForumTag
.
count
({
ent_code
:
req
.
session
.
user
.
ent_code
},
function
(
err
,
count
)
{
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
ForumTag
.
find
({
ent_code
:
req
.
session
.
user
.
ent_code
},
null
,
{
skip
:
skip
,
limit
:
limit
},
function
(
err
,
docs
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
total
=
count
;
rs
.
pageNo
=
pageNo
;
rs
.
pageSize
=
pageSize
;
rs
.
items
=
docs
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
});
//查询标签下的文章列表
router
.
get
(
'/tag/:tid/threads'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
tid
=
req
.
params
.
tid
;
var
rs
=
{};
var
group
=
new
ForumGroup
(
req
.
body
);
ForumThread
.
count
({
ent_code
:
req
.
session
.
user
.
ent_code
,
tag
:
tid
},
function
(
err
,
count
)
{
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
ForumThread
.
find
({
ent_code
:
req
.
session
.
user
.
ent_code
,
tag
:
tid
},
null
,
{
skip
:
skip
,
limit
:
limit
},
function
(
err
,
docs
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
total
=
count
;
rs
.
pageNo
=
pageNo
;
rs
.
pageSize
=
pageSize
;
rs
.
items
=
docs
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
});
\ No newline at end of file
app/controllers/mobile/forumThread.js
0 → 100644
View file @
dc86d020
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
ForumThread
=
mongoose
.
model
(
'ForumThread'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
forumRolePermissionService
=
require
(
'../../service/forumRolePermissionService'
);
var
forumPraiseLogService
=
require
(
'../../service/forumPraiseLogService'
);
var
forumShareLogService
=
require
(
'../../service/forumShareLogService'
);
var
forumCommentService
=
require
(
'../../service/forumCommentService'
);
var
async
=
require
(
'async'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
};
//---------------------文章表单操作---------------------------------
//新增论坛文章
router
.
post
(
'/thread/create'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{};
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
forumThreadService
.
createThread
(
req
.
body
,
function
(
err
,
entity
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
{
'id'
:
entity
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
});
//获取目标论坛文章
router
.
get
(
'/thread/:tid/get'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
rs
=
{};
if
(
tid
)
{
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
thread
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//更新文章状态、如:屏蔽
router
.
post
(
'/thread/:tid/update'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
if
(
tid
){
forumThreadService
.
updateThreadById
(
tid
,
req
.
body
,
function
(
err
,
thread
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//删除文章
router
.
post
(
'/thread/:tid/delete'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
if
(
tid
){
forumThreadService
.
deleteThreadById
(
tid
,
function
(
err
,
thread
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//文章点赞
router
.
post
(
'/thread/:tid/raise'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
){
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
req
.
body
.
action
,
integral
,
exp
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
//有操作权限
//2.获取论坛文章
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
){
//3.更新文章统计数据(点赞数)
if
(
thread
){
var
raiseCount
=
thread
.
praise_count
||
0
;
raiseCount
=
Number
(
raiseCount
)
+
Number
(
1
);
forumThreadService
.
updateThreadById
(
tid
,{
praise_count
:
raiseCount
},
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
else
{
callback
(
'cannot find thread by id'
,
null
);
}
},
function
(
callback
){
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
user
:
req
.
session
.
openUser
.
openId
,
thread
:
tid
,
ip
:
req
.
ip
};
//4.创建点赞日志
forumPraiseLogService
.
createPraiseLog
(
entity
,
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
],
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//文章分享
router
.
post
(
'/thread/:tid/share'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
){
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
var
destination
=
req
.
body
.
destination
||
'1'
;
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
req
.
body
.
action
,
integral
,
exp
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
//有操作权限
//2.获取论坛文章
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
){
//3.更新文章统计数据(分享数)
if
(
thread
){
var
shareCount
=
thread
.
share_count
||
0
;
shareCount
=
Number
(
shareCount
)
+
Number
(
1
);
forumThreadService
.
updateThreadById
(
tid
,{
share_count
:
shareCount
},
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
else
{
callback
(
'cannot find thread by id'
,
null
);
}
},
function
(
callback
){
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
user
:
req
.
session
.
openUser
.
openId
,
thread
:
tid
,
destination
:
destination
,
ip
:
req
.
ip
};
//4.创建分享日志
forumShareLogService
.
createShareLog
(
entity
,
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
],
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//新增文章评论
/**
**输入:
tid:文章id
pId:评论父id
comment:评论内容
**输出:
操作结果
**/
router
.
post
(
'/thread/:tid/comment/create'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
){
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
var
destination
=
req
.
body
.
destination
||
'1'
;
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
req
.
body
.
action
,
integral
,
exp
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
//有操作权限
var
content
=
req
.
body
.
content
;
if
(
content
){
//评论不能为空
//2.获取论坛文章
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
){
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
from
:
req
.
session
.
openUser
.
openId
,
to
:
req
.
session
.
openUser
.
openId
,
content
:
content
,
ip
:
req
.
ip
};
//4.创建文章评论
forumCommentService
.
createComment
(
entity
,
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
var
comments
=
thread
.
comments
;
var
array
=
[];
if
(
comments
&&
comments
.
length
>
0
){
array
=
comments
;
}
array
.
push
(
result
.
_id
);
forumThreadService
.
updateThreadById
(
tid
,{
comments
:
array
},
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
});
},
function
(
callback
){
//3.更新文章统计数据(评论数)
if
(
thread
){
var
commentCount
=
thread
.
comment_count
||
0
;
commentCount
=
Number
(
commentCount
)
+
Number
(
1
);
forumThreadService
.
updateThreadById
(
tid
,{
comment_count
:
commentCount
},
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
else
{
callback
(
'cannot find thread by id'
,
null
);
}
}
],
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//新建文章评论的子评论
router
.
post
(
'/thread/:tid/comment/:cid/create'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
if
(
tid
&&
cid
){
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
var
destination
=
req
.
body
.
destination
||
'1'
;
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
req
.
body
.
action
,
integral
,
exp
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
//有操作权限
var
content
=
req
.
body
.
content
;
if
(
content
){
//评论不能为空
//2.获取论坛评论
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
comment
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
){
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
from
:
req
.
session
.
openUser
.
openId
,
to
:
req
.
session
.
openUser
.
openId
,
content
:
content
,
ip
:
req
.
ip
};
//4.创建文章评论
forumCommentService
.
createComment
(
entity
,
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
var
comments
=
comment
.
comments
;
var
array
=
[];
if
(
comments
&&
comments
.
length
>
0
){
array
=
comments
;
}
array
.
push
(
result
.
_id
);
forumCommentService
.
updateCommentById
(
cid
,{
comments
:
array
},
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
});
}
],
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//删除文章评论
router
.
post
(
'/thread/:tid/comment/:cid/delete'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
body
.
tid
||
null
;
console
.
log
(
tid
);
//1.检查是否有权限
//2.获取论坛文章
//3.新增文章评论
//4.更新文章统计数据(评论数)
});
//更新文章评论状态为:显示/不显示
router
.
post
(
'/thread/:tid/comment/:cid/:status'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
var
status
=
req
.
params
.
status
||
null
;
if
(
tid
&&
cid
&&
status
){
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
comment
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumCommentService
.
updateThreadById
(
cid
,{
status
:
status
},
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
\ 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