Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qinhaitao
taobao-mini-template
Commits
0369b72d
Commit
0369b72d
authored
Sep 15, 2020
by
maggie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加排名查询service
parent
71bb98fe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
0 deletions
+56
-0
user.service.ts
v2.0/src/service/user.service.ts
+56
-0
No files found.
v2.0/src/service/user.service.ts
View file @
0369b72d
...
...
@@ -182,6 +182,62 @@ class UserService extends BaseService {
async
updateUser
(
_id
:
string
,
projection
:
IUpdateQuery
)
{
return
await
this
.
userdao
.
update
({
_id
},
this
.
formatUpdateUserProjection
(
projection
))
}
/**
* @desc 排行榜
* @param {查询条件} match
* @param {排序规则} sort
* @param {查询条数} limit
*/
async
getRank
(
match
:
Object
,
sort
:
Object
,
limit
:
number
)
{
const
{
data
}
=
this
.
context
const
{
activityId
}
=
data
return
await
this
.
userdao
.
aggregate
([
{
$match
:
{
...
match
,
activityId
}
},
{
$sort
:
sort
},
{
$group
:
{
_id
:
null
,
table
:
{
$push
:
'$$ROOT'
}
}
},
{
$unwind
:
{
path
:
'$table'
,
includeArrayIndex
:
'no'
}
},
{
$project
:
{
_id
:
0
,
openId
:
'$table.openId'
,
userNick
:
'$table.userNick'
,
no
:
{
$add
:
[
'$no'
,
1
]
}
}
},
{
$limit
:
limit
}
])
}
/**
* @desc 获取我的排名
* @param {查询条件} match
* @param {排序规则} sort
*/
async
getMyRank
(
match
:
Object
,
sort
:
Object
)
{
const
{
openId
,
data
}
=
this
.
context
const
{
activityId
}
=
data
return
await
this
.
userdao
.
aggregate
([
{
$match
:
{
...
match
,
activityId
}
},
{
$sort
:
sort
},
{
$group
:
{
_id
:
null
,
table
:
{
$push
:
'$$ROOT'
}
}
},
{
$unwind
:
{
path
:
'$table'
,
includeArrayIndex
:
'no'
}
},
{
$project
:
{
_id
:
0
,
openId
:
'$table.openId'
,
userNick
:
'$table.userNick'
,
no
:
{
$add
:
[
'$no'
,
1
]
}
}
},
{
$match
:
{
openId
}
}
])
}
/**
* updateUser projection 格式化
*
...
...
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