Commit 811ef1b2 authored by qinhaitao's avatar qinhaitao

feat: 🎸 增加 await

parent 03c6bb44
/** @format */
import { services, checkParams, registeInfos } from '../decorator/common'
import { services, checkParams, preUpdate } from '../decorator/common'
import { resultsModel } from '../sdk'
import { UserService, AccessService } from '../service'
import { UserService } from '../service'
export default class User {
/**
* 获取游戏信息
*
* needKeys 根据需求自取字段 格式: { gameTimes: 1}
*/
@checkParams(['activityId', 'needKeys'])
@services([UserService, AccessService])
@services([UserService])
async getGameInfo(
context: IContext<IParams>,
{ userInfo, activityInfo }: IControllerInfos,
[userService, accessService]: [UserService, AccessService]
[userService]: [UserService]
) {
const { needKeys } = context.data
const gameInfoResult = await userService.getUserInfo(needKeys)
return resultsModel.success({
...gameInfoResult
})
}
}
......@@ -23,7 +23,7 @@ export default class Task {
[taskService]: [TaskService]
): Promise<IResult<{ list: ITaskInfo[] }>> {
// 读取B端 tasks字段配置自动生成任务列表
const result = taskService.initTaskList(userInfo, activityInfo)
const result = await taskService.initTaskList(userInfo, activityInfo)
return resultsModel.success({
...result
......@@ -88,7 +88,7 @@ export default class Task {
const list = await baseService.getItemListByIds(itemIds, session)
const listWithCollectStatus = taskService.getItemListWithCollectStatus(list, userInfo)
const listWithCollectStatus = await taskService.getItemListWithCollectStatus(list, userInfo)
return resultsModel.success(listWithCollectStatus)
}
......
/** @format */
import { isArray, isEmpty, isObject, merge } from 'lodash'
import { isEmpty, merge } from 'lodash'
import { UserService } from '../../service'
import { recordErrorLog } from '../../utils/common/logger'
import { resultsModel } from '../../sdk'
......
......@@ -7,10 +7,12 @@ import AwardsController from './controller/awards.controller'
import ShareController from './controller/share.controller'
import StatController from './controller/stat.controller'
import LoginController from './controller/login.controller'
import GameController from './controller/game.controller'
const { getVipInfo, getRankList } = new UserController()
const { login } = new LoginController()
const { getGameInfo } = new GameController()
const {
getTaskList,
receiveTaskRewards,
......@@ -39,5 +41,6 @@ export default {
doHelp,
getStats,
addStat,
getRankList
getRankList,
getGameInfo
}
......@@ -29,7 +29,7 @@ export default class TaskService extends UserService {
}
// 根据活动tasks字段渲染任务
initTaskList(userInfo: IUserInfo, activityInfo: IActivityInfo) {
async initTaskList(userInfo: IUserInfo, activityInfo: IActivityInfo) {
return {
list: Object.keys(activityInfo?.tasks || {}).map((task: ITaskType) => {
return this.initTask(task, activityInfo?.tasks?.[task]?.title, userInfo, activityInfo)
......@@ -115,7 +115,8 @@ export default class TaskService extends UserService {
async completeTask(
taskType: ITaskType,
activityInfo: IActivityInfo,
userInfo: IUserInfo
userInfo: IUserInfo,
customRecord: Object = {}
): Promise<boolean | ICodeType> {
const today = getToday()
const rewards = activityInfo?.tasks?.[taskType]?.value || 0
......@@ -124,7 +125,7 @@ export default class TaskService extends UserService {
data: { itemId }
} = this.context
const record = { itemId, openId: taskType === 'invites' ? openId : undefined }
const record = { itemId, openId: taskType === 'invites' ? openId : undefined, ...customRecord }
const result = await this.updateUser(userInfo._id, {
$inc: {
[`remainTimes.${taskType}`]: rewards
......@@ -196,7 +197,7 @@ export default class TaskService extends UserService {
return projection
}
getItemListWithCollectStatus(list: ITaoBaoItems[], userInfo: IUserInfo) {
async getItemListWithCollectStatus(list: ITaoBaoItems[], userInfo: IUserInfo) {
const { taskInfo } = getTotalCompleteTask('collectGoods', userInfo)
return list.map(v => {
......
......@@ -21,10 +21,10 @@ class UserService extends BaseService {
* @desc 获取当前打开活动的用户详情
* @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象)
*/
async getUserInfo(projection: IFindProjection = {}) {
async getUserInfo(projection = {}) {
let { openId, data } = this.context
let { activityId } = data
return await this.userdao.findOne<IUserInfo>({ openId, activityId }, projection)
return await this.userdao.findOne<IUserInfo>({ openId, activityId }, { projection })
}
/**
......
......@@ -2,13 +2,15 @@
import updateVip from './updateVip'
import updateSignTask from './updateSignTask'
import updateOrderGoods from './updateOrderGoods'
import updateFirstLogin from './updateFirstLogin'
const update = {
updateVip,
updateSignTask,
updateOrderGoods
updateOrderGoods,
updateFirstLogin
}
export default update
export { updateVip, updateSignTask, updateOrderGoods }
export { updateVip, updateSignTask, updateOrderGoods, updateFirstLogin }
/** @format */
import { getToday } from '../getToday'
import { isNewVip, setNewVipUserData } from '../userUpdate'
export default async function updateFirstLogin(
context: IContext<IParams>,
{ vipInfo, userInfo, activityInfo }: IControllerInfos
): Promise<IPreUpdateQuery> {
let { member } = userInfo
const memberReWards = activityInfo?.tasks?.member?.value
return isNewVip(userInfo, vipInfo)
? {
$set: {
member: setNewVipUserData(member)
},
$inc: {
'remainTimes.member': +memberReWards
},
$push: {
[`taskInfo.${getToday()}.member`]: { creatTime: Date.now() }
}
}
: {}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment