Commit 43b8148d authored by qinhaitao's avatar qinhaitao

feat: 🎸 findone 加入类型推断

parent c98685f5
/** @format */ /** @format */
import { AwardsService } from '../service'; import { AwardsService } from '../service';
import { CodeType } from 'taobao-mini-sdk/lib/utils/codetypes';
export interface IPrizeListParams { export interface IPrizeListParams {
activityId: string; activityId: string;
} }
...@@ -39,7 +40,7 @@ export default class AwardsController { ...@@ -39,7 +40,7 @@ export default class AwardsController {
name: string; name: string;
}; };
}, true> | import("taobao-mini-sdk/lib/utils/resultmodel").Result<{ }, true> | import("taobao-mini-sdk/lib/utils/resultmodel").Result<{
id: any; id: number | CodeType;
type: number; type: number;
name: string; name: string;
image: string; image: string;
......
...@@ -87,6 +87,7 @@ var Task = /** @class */ (function () { ...@@ -87,6 +87,7 @@ var Task = /** @class */ (function () {
updatedUserInfo = _c.sent(); updatedUserInfo = _c.sent();
if (!updatedUserInfo) if (!updatedUserInfo)
return [2 /*return*/, sdk_1.resultsModel.error(constants_1.CODE_TYPES.SYSTEM_ERROR, '更新任务列表失败') return [2 /*return*/, sdk_1.resultsModel.error(constants_1.CODE_TYPES.SYSTEM_ERROR, '更新任务列表失败')
// 返回对应的任务时, B端b_activity_config tasks 需配置对应的任务
// 会员任务 // 会员任务
]; ];
vipTask = taskService.initVipTask(updatedUserInfo, vipInfo, tasks); vipTask = taskService.initVipTask(updatedUserInfo, vipInfo, tasks);
......
This diff is collapsed.
...@@ -11,6 +11,6 @@ export default class UserAccessService { ...@@ -11,6 +11,6 @@ export default class UserAccessService {
* 增加访问记录 * 增加访问记录
* @param {是否关注店铺} isFollow * @param {是否关注店铺} isFollow
*/ */
addAccess(isFollow: boolean, isVip: boolean): Promise<any>; addAccess(isFollow: boolean, isVip: boolean): Promise<number>;
getAccessCount(): Promise<any>; getAccessCount(): Promise<number>;
} }
...@@ -13,7 +13,7 @@ export default class AwardsService extends UserService { ...@@ -13,7 +13,7 @@ export default class AwardsService extends UserService {
* 插入奖品记录 * 插入奖品记录
* @param {*} award * @param {*} award
*/ */
addAward(award: IAwards): Promise<any>; addAward(award: IAwards): Promise<number | import("taobao-mini-sdk/lib/utils/codetypes").CodeType>;
/** /**
* 发放奖品 * 发放奖品
* @param {*} document * @param {*} document
...@@ -46,5 +46,5 @@ export default class AwardsService extends UserService { ...@@ -46,5 +46,5 @@ export default class AwardsService extends UserService {
* 获取活动配置项奖品 * 获取活动配置项奖品
* @param {string} _id * @param {string} _id
*/ */
getActivityPrizeById(_id: string): Promise<any>; getActivityPrizeById(_id: string): Promise<unknown>;
} }
...@@ -240,6 +240,7 @@ var AwardsService = /** @class */ (function (_super) { ...@@ -240,6 +240,7 @@ var AwardsService = /** @class */ (function (_super) {
} }
} }
v.expiredTime = awardReceiveExpiredTime; v.expiredTime = awardReceiveExpiredTime;
return v;
}); });
} }
return [2 /*return*/, myprizeList]; return [2 /*return*/, myprizeList];
......
This diff is collapsed.
...@@ -11,14 +11,14 @@ declare class UserService extends BaseService { ...@@ -11,14 +11,14 @@ declare class UserService extends BaseService {
* @desc 获取当前打开活动的用户详情 * @desc 获取当前打开活动的用户详情
* @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象) * @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象)
*/ */
getUserInfo(): Promise<any>; getUserInfo(): Promise<IUserInfo>;
/** /**
* @desc 根据inviteId获取用户详情 * @desc 根据inviteId获取用户详情
* @desc 常用于助力分享码为用户openId, 被邀请人打开活动助力时需要获取邀请人的用户详情 * @desc 常用于助力分享码为用户openId, 被邀请人打开活动助力时需要获取邀请人的用户详情
* @param {邀请人的openId} inviteId * @param {邀请人的openId} inviteId
* @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象) * @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象)
*/ */
getUserInfoByOpenId(inviteId: string): Promise<any>; getUserInfoByOpenId(inviteId: string): Promise<IUserInfo>;
/** /**
* @desc 获取是否是会员 * @desc 获取是否是会员
* @param {调用淘宝接口的session} session * @param {调用淘宝接口的session} session
...@@ -33,7 +33,7 @@ declare class UserService extends BaseService { ...@@ -33,7 +33,7 @@ declare class UserService extends BaseService {
* @returns * @returns
* @memberof UserService * @memberof UserService
*/ */
initUserData(vipInfo: IVipInfo, activityInfo: IActivityInfo): Promise<any>; initUserData(vipInfo: IVipInfo, activityInfo: IActivityInfo): Promise<number>;
updateUserData(vipInfo: IVipInfo, userInfo: IUserInfo, activityInfo: IActivityInfo): Promise<void>; updateUserData(vipInfo: IVipInfo, userInfo: IUserInfo, activityInfo: IActivityInfo): Promise<void>;
/** /**
* @desc 更新用户表 * @desc 更新用户表
...@@ -47,7 +47,7 @@ declare class UserService extends BaseService { ...@@ -47,7 +47,7 @@ declare class UserService extends BaseService {
* @param {用户的主键id} _id * @param {用户的主键id} _id
* @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象) * @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象)
*/ */
getUserInfoById(_id: string): Promise<any>; getUserInfoById(_id: string): Promise<unknown>;
/** /**
*判断是否新会员 *判断是否新会员
* *
......
This diff is collapsed.
...@@ -7,6 +7,6 @@ export declare const getSellerSession: (context: IContext<IParams>, activityId?: ...@@ -7,6 +7,6 @@ export declare const getSellerSession: (context: IContext<IParams>, activityId?:
session?: undefined; session?: undefined;
userNick?: undefined; userNick?: undefined;
} | { } | {
session: any; session: string;
userNick: any; userNick: string;
}>; }>;
{"version":3,"file":"getSession.js","sourceRoot":"","sources":["../../../src/utils/package/getSession.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+BAAuE;AAEvE,iCAAmC;AAEtB,QAAA,gBAAgB,GAAG,UAAO,OAA0B,EAAE,UAAmB;;;;;gBACpF,IAAI,CAAC,UAAU,EAAE;oBACf,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAA;iBACrC;gBACG,WAAW,GAAa,IAAI,aAAO,CAAC,OAAO,EAAE,4BAAuB,CAAC,CAAA;g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EAAE,oBAAoB,CAAC,MAAM;qBACpC,CAAC;oBACF,2CAA2C;kBADzC;;gBAFE,MAAM,GAAG,SAEX;gBACF,2CAA2C;gBAC3C,IAAI,CAAC,MAAM;oBAAE,sBAAO,EAAE,EAAA;gBACtB,sBAAO;wBACL,OAAO,EAAE,MAAM,CAAC,WAAW;wBAC3B,QAAQ,EAAE,MAAM,CAAC,QAAQ;qBAC1B,EAAA;;;KACF,CAAA"}
\ No newline at end of file \ No newline at end of file
export declare const logFn: (context: IContext<IParams>) => void; export declare const logFn: (context: IContext<IParams>) => void;
export declare const recordErrorLog: (context: IContext<IParams>, baseInfos: IControllerInfos, errorMsg: string, stack: string) => Promise<any>; export declare const recordErrorLog: (context: IContext<IParams>, baseInfos: IControllerInfos, errorMsg: string, stack: string) => Promise<number>;
export declare const logger: (message: any) => void; export declare const logger: (message: any) => void;
...@@ -21,7 +21,7 @@ export default class AwardsService extends UserService { ...@@ -21,7 +21,7 @@ export default class AwardsService extends UserService {
// 根据奖品Id扣库存, 扣库存成功返回为1 // 根据奖品Id扣库存, 扣库存成功返回为1
async reduceStock(_id: string) { async reduceStock(_id: string) {
let result = await this.activityprizedao.findOne({ _id, deleteStatus: ACTIVITY_STATUS.NORMAL }) let result = await this.activityprizedao.findOne<IActivityPrize>({ _id, deleteStatus: ACTIVITY_STATUS.NORMAL })
// 奖品不存在 // 奖品不存在
if (!result) { if (!result) {
return CODE_TYPES.ERROR_NO_PRIZE return CODE_TYPES.ERROR_NO_PRIZE
...@@ -106,7 +106,7 @@ export default class AwardsService extends UserService { ...@@ -106,7 +106,7 @@ export default class AwardsService extends UserService {
async getMyPrizeList({ openId, activityId }: { openId: string; activityId: string }): Promise<Array<IAwards>> { async getMyPrizeList({ openId, activityId }: { openId: string; activityId: string }): Promise<Array<IAwards>> {
// 获取奖品领取过期时间 // 获取奖品领取过期时间
let { awardReceiveExpiredTime } = await this.getBaseInfo(activityId) let { awardReceiveExpiredTime } = await this.getBaseInfo(activityId)
let myprizeList = await this.awardsdao.find( let myprizeList = await this.awardsdao.find<IAwards>(
{ openId, activityId }, { openId, activityId },
{ {
projection: { projection: {
...@@ -144,7 +144,7 @@ export default class AwardsService extends UserService { ...@@ -144,7 +144,7 @@ export default class AwardsService extends UserService {
// 若有过期时间,且已过期 // 若有过期时间,且已过期
if (awardReceiveExpiredTime) { if (awardReceiveExpiredTime) {
let currentTime = Date.now() let currentTime = Date.now()
myprizeList = myprizeList.map((v: { drawStatus: number; remark: string; expiredTime: any }) => { myprizeList = myprizeList.map(v => {
if (currentTime > awardReceiveExpiredTime) { if (currentTime > awardReceiveExpiredTime) {
if ([DRAW_STATUS.WAITAWARD, DRAW_STATUS.RETRY].includes(v.drawStatus)) { if ([DRAW_STATUS.WAITAWARD, DRAW_STATUS.RETRY].includes(v.drawStatus)) {
v.drawStatus = DRAW_STATUS.EXPIRED v.drawStatus = DRAW_STATUS.EXPIRED
...@@ -152,6 +152,7 @@ export default class AwardsService extends UserService { ...@@ -152,6 +152,7 @@ export default class AwardsService extends UserService {
} }
} }
v.expiredTime = awardReceiveExpiredTime v.expiredTime = awardReceiveExpiredTime
return v
}) })
} }
return myprizeList return myprizeList
...@@ -183,7 +184,7 @@ export default class AwardsService extends UserService { ...@@ -183,7 +184,7 @@ export default class AwardsService extends UserService {
if (awardReceiveExpiredTime && Date.now() > awardReceiveExpiredTime) { if (awardReceiveExpiredTime && Date.now() > awardReceiveExpiredTime) {
return CODE_TYPES.ERROR_PRIZE_EXPIRED return CODE_TYPES.ERROR_PRIZE_EXPIRED
} }
let award = await this.awardsdao.findOne({ _id }) let award = await this.awardsdao.findOne<IAwards>({ _id })
console.log(`receiveObject-award`, award) console.log(`receiveObject-award`, award)
// 奖品不存在 // 奖品不存在
if (!award) { if (!award) {
...@@ -229,7 +230,7 @@ export default class AwardsService extends UserService { ...@@ -229,7 +230,7 @@ export default class AwardsService extends UserService {
return CODE_TYPES.ERROR_PRIZE_EXPIRED return CODE_TYPES.ERROR_PRIZE_EXPIRED
} }
let result: {} = {} let result: {} = {}
let award = await this.awardsdao.findOne({ _id }) let award = await this.awardsdao.findOne<IAwards>({ _id })
// 奖品不存在 // 奖品不存在
if (!award) { if (!award) {
return CODE_TYPES.ERROR_NO_PRIZE return CODE_TYPES.ERROR_NO_PRIZE
......
...@@ -23,7 +23,7 @@ class UserService extends BaseService { ...@@ -23,7 +23,7 @@ class UserService extends BaseService {
async getUserInfo() { async getUserInfo() {
let { openId, data } = this.context let { openId, data } = this.context
let { activityId } = data let { activityId } = data
let record = await this.userdao.findOne({ openId, activityId }) let record = await this.userdao.findOne<IUserInfo>({ openId, activityId })
return record return record
} }
...@@ -35,7 +35,7 @@ class UserService extends BaseService { ...@@ -35,7 +35,7 @@ class UserService extends BaseService {
*/ */
async getUserInfoByOpenId(inviteId: string) { async getUserInfoByOpenId(inviteId: string) {
let { activityId } = this.context.data let { activityId } = this.context.data
let record = await this.userdao.findOne({ openId: inviteId, activityId }) let record = await this.userdao.findOne<IUserInfo>({ openId: inviteId, activityId })
return record return record
} }
......
...@@ -26,4 +26,5 @@ interface IAwards { ...@@ -26,4 +26,5 @@ interface IAwards {
createTime?: number createTime?: number
updateTime?: number updateTime?: number
awardsType?: string awardsType?: string
expiredTime?: number
} }
/** @format */
interface IBaseDao {
dbName: string
db: object
constructor(context: any, dbName: string)
/**
* 查询一条数据
* @param query
* @param projection
*/
findOne<T>(query: object, projection?: object): Promise<T | undefined>
/**
* 查询多条数据
* @param query
* @param projection
*/
find<T>(query: object, projection?: object): Promise<T[]>
/**
* 插入单条数据
* @param document
*/
insertOne(document: object): Promise<number>
/**
* 插入多条数据
* @param documents 插入对象
*/
insertMany(documents: object[]): Promise<number[]>
/**
* 更新数据
* @param query
* @param options
*/
update(query: object, options?: object): Promise<any>
/**
* 删除多条数据
* @param filter
*/
delete(filter: object): Promise<any>
/**
* 获取条目数
* @param query
* @param options
*/
count(query: object, options?: object): Promise<number>
/**
* 聚合查询
* @param query
* @param options
*/
aggregate(aggregateOperation: object | any[]): Promise<any>
}
...@@ -35,54 +35,3 @@ interface IVipInfo { ...@@ -35,54 +35,3 @@ interface IVipInfo {
isVip: boolean isVip: boolean
url?: string url?: string
} }
interface IBaseDao {
dbName: string
db: object
constructor(context: any, dbName: string)
/**
* 查询一条数据
* @param query
* @param projection
*/
findOne(query: object, projection?: object): Promise<any>
/**
* 查询多条数据
* @param query
* @param projection
*/
find(query: object, projection?: object): Promise<any>
/**
* 插入单条数据
* @param document
*/
insertOne(document: object): Promise<any>
/**
* 插入多条数据
* @param documents 插入对象
*/
insertMany(documents: object[]): Promise<any>
/**
* 更新数据
* @param query
* @param options
*/
update(query: object, options?: object): Promise<any>
/**
* 删除多条数据
* @param filter
*/
delete(filter: object): Promise<any>
/**
* 获取条目数
* @param query
* @param options
*/
count(query: object, options?: object): Promise<any>
/**
* 聚合查询
* @param query
* @param options
*/
aggregate(aggregateOperation: object | any[]): Promise<any>
}
/** @format */
interface ISellerInfo {
accessToken: string
openId: string
appkey: string
userNick: string
shopId?: string
appOwnerOpenId: string
createTime: number
updateTime: number
}
...@@ -14,10 +14,10 @@ export const getSellerSession = async (context: IContext<IParams>, activityId?: ...@@ -14,10 +14,10 @@ export const getSellerSession = async (context: IContext<IParams>, activityId?:
} }
let activitydao: IBaseDao = new BaseDao(context, ACTIVITY_CONFIG_DB_NAME) let activitydao: IBaseDao = new BaseDao(context, ACTIVITY_CONFIG_DB_NAME)
let sellerdao: IBaseDao = new BaseDao(context, SELLER_INFO_DB_NAME) let sellerdao: IBaseDao = new BaseDao(context, SELLER_INFO_DB_NAME)
let activityConfigResult = await activitydao.findOne({ _id: activityId }) let activityConfigResult = await activitydao.findOne<IActivityInfo>({ _id: activityId })
if (!activityConfigResult) return {} if (!activityConfigResult) return {}
let result = await sellerdao.findOne({ let result = await sellerdao.findOne<ISellerInfo>({
openId: activityConfigResult.openId openId: activityConfigResult.openId
}) })
// console.log(`getSellerSession`, result) // console.log(`getSellerSession`, result)
......
...@@ -21,4 +21,4 @@ ...@@ -21,4 +21,4 @@
"include": [ "include": [
"./src/**/*" "./src/**/*"
] ]
} }
\ No newline at end of file \ No newline at end of file
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