Commit 43b8148d authored by qinhaitao's avatar qinhaitao

feat: 🎸 findone 加入类型推断

parent c98685f5
/** @format */
import { AwardsService } from '../service';
import { CodeType } from 'taobao-mini-sdk/lib/utils/codetypes';
export interface IPrizeListParams {
activityId: string;
}
......@@ -39,7 +40,7 @@ export default class AwardsController {
name: string;
};
}, true> | import("taobao-mini-sdk/lib/utils/resultmodel").Result<{
id: any;
id: number | CodeType;
type: number;
name: string;
image: string;
......
......@@ -87,6 +87,7 @@ var Task = /** @class */ (function () {
updatedUserInfo = _c.sent();
if (!updatedUserInfo)
return [2 /*return*/, sdk_1.resultsModel.error(constants_1.CODE_TYPES.SYSTEM_ERROR, '更新任务列表失败')
// 返回对应的任务时, B端b_activity_config tasks 需配置对应的任务
// 会员任务
];
vipTask = taskService.initVipTask(updatedUserInfo, vipInfo, tasks);
......
This diff is collapsed.
......@@ -11,6 +11,6 @@ export default class UserAccessService {
* 增加访问记录
* @param {是否关注店铺} isFollow
*/
addAccess(isFollow: boolean, isVip: boolean): Promise<any>;
getAccessCount(): Promise<any>;
addAccess(isFollow: boolean, isVip: boolean): Promise<number>;
getAccessCount(): Promise<number>;
}
......@@ -13,7 +13,7 @@ export default class AwardsService extends UserService {
* 插入奖品记录
* @param {*} award
*/
addAward(award: IAwards): Promise<any>;
addAward(award: IAwards): Promise<number | import("taobao-mini-sdk/lib/utils/codetypes").CodeType>;
/**
* 发放奖品
* @param {*} document
......@@ -46,5 +46,5 @@ export default class AwardsService extends UserService {
* 获取活动配置项奖品
* @param {string} _id
*/
getActivityPrizeById(_id: string): Promise<any>;
getActivityPrizeById(_id: string): Promise<unknown>;
}
......@@ -240,6 +240,7 @@ var AwardsService = /** @class */ (function (_super) {
}
}
v.expiredTime = awardReceiveExpiredTime;
return v;
});
}
return [2 /*return*/, myprizeList];
......
This diff is collapsed.
......@@ -11,14 +11,14 @@ declare class UserService extends BaseService {
* @desc 获取当前打开活动的用户详情
* @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象)
*/
getUserInfo(): Promise<any>;
getUserInfo(): Promise<IUserInfo>;
/**
* @desc 根据inviteId获取用户详情
* @desc 常用于助力分享码为用户openId, 被邀请人打开活动助力时需要获取邀请人的用户详情
* @param {邀请人的openId} inviteId
* @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象)
*/
getUserInfoByOpenId(inviteId: string): Promise<any>;
getUserInfoByOpenId(inviteId: string): Promise<IUserInfo>;
/**
* @desc 获取是否是会员
* @param {调用淘宝接口的session} session
......@@ -33,7 +33,7 @@ declare class UserService extends BaseService {
* @returns
* @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>;
/**
* @desc 更新用户表
......@@ -47,7 +47,7 @@ declare class UserService extends BaseService {
* @param {用户的主键id} _id
* @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?:
session?: undefined;
userNick?: undefined;
} | {
session: any;
userNick: any;
session: string;
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;gBACrE,SAAS,GAAa,IAAI,aAAO,CAAC,OAAO,EAAE,wBAAmB,CAAC,CAAA;gBACxC,qBAAM,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,EAAA;;gBAArE,oBAAoB,GAAG,SAA8C;gBACzE,IAAI,CAAC,oBAAoB;oBAAE,sBAAO,EAAE,EAAA;gBAEvB,qBAAM,SAAS,CAAC,OAAO,CAAC;wBACnC,MAAM,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
{"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;gBACrE,SAAS,GAAa,IAAI,aAAO,CAAC,OAAO,EAAE,wBAAmB,CAAC,CAAA;gBACxC,qBAAM,WAAW,CAAC,OAAO,CAAgB,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,EAAA;;gBAApF,oBAAoB,GAAG,SAA6D;gBACxF,IAAI,CAAC,oBAAoB;oBAAE,sBAAO,EAAE,EAAA;gBAEvB,qBAAM,SAAS,CAAC,OAAO,CAAc;wBAChD,MAAM,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
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;
......@@ -21,7 +21,7 @@ export default class AwardsService extends UserService {
// 根据奖品Id扣库存, 扣库存成功返回为1
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) {
return CODE_TYPES.ERROR_NO_PRIZE
......@@ -106,7 +106,7 @@ export default class AwardsService extends UserService {
async getMyPrizeList({ openId, activityId }: { openId: string; activityId: string }): Promise<Array<IAwards>> {
// 获取奖品领取过期时间
let { awardReceiveExpiredTime } = await this.getBaseInfo(activityId)
let myprizeList = await this.awardsdao.find(
let myprizeList = await this.awardsdao.find<IAwards>(
{ openId, activityId },
{
projection: {
......@@ -144,7 +144,7 @@ export default class AwardsService extends UserService {
// 若有过期时间,且已过期
if (awardReceiveExpiredTime) {
let currentTime = Date.now()
myprizeList = myprizeList.map((v: { drawStatus: number; remark: string; expiredTime: any }) => {
myprizeList = myprizeList.map(v => {
if (currentTime > awardReceiveExpiredTime) {
if ([DRAW_STATUS.WAITAWARD, DRAW_STATUS.RETRY].includes(v.drawStatus)) {
v.drawStatus = DRAW_STATUS.EXPIRED
......@@ -152,6 +152,7 @@ export default class AwardsService extends UserService {
}
}
v.expiredTime = awardReceiveExpiredTime
return v
})
}
return myprizeList
......@@ -183,7 +184,7 @@ export default class AwardsService extends UserService {
if (awardReceiveExpiredTime && Date.now() > awardReceiveExpiredTime) {
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)
// 奖品不存在
if (!award) {
......@@ -229,7 +230,7 @@ export default class AwardsService extends UserService {
return CODE_TYPES.ERROR_PRIZE_EXPIRED
}
let result: {} = {}
let award = await this.awardsdao.findOne({ _id })
let award = await this.awardsdao.findOne<IAwards>({ _id })
// 奖品不存在
if (!award) {
return CODE_TYPES.ERROR_NO_PRIZE
......
......@@ -23,7 +23,7 @@ class UserService extends BaseService {
async getUserInfo() {
let { openId, data } = this.context
let { activityId } = data
let record = await this.userdao.findOne({ openId, activityId })
let record = await this.userdao.findOne<IUserInfo>({ openId, activityId })
return record
}
......@@ -35,7 +35,7 @@ class UserService extends BaseService {
*/
async getUserInfoByOpenId(inviteId: string) {
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
}
......
......@@ -26,4 +26,5 @@ interface IAwards {
createTime?: number
updateTime?: number
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 {
isVip: boolean
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?:
}
let activitydao: IBaseDao = new BaseDao(context, ACTIVITY_CONFIG_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 {}
let result = await sellerdao.findOne({
let result = await sellerdao.findOne<ISellerInfo>({
openId: activityConfigResult.openId
})
// console.log(`getSellerSession`, result)
......
{
"compileOnSave": true,
"compilerOptions": {
"target": "es5",
"lib": [
"es6", "dom", "es7"
],
"typeRoots": ["./node_modules/@types/", "./src/typings/"],
"outDir": "./dist",
"sourceMap": true,
"module": "commonjs",
"watch": true,
"moduleResolution": "node",
"allowJs": true,
"isolatedModules": false,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"suppressImplicitAnyIndexErrors": true
},
"include": [
"./src/**/*"
]
}
\ No newline at end of file
"compileOnSave": true,
"compilerOptions": {
"target": "es5",
"lib": [
"es6", "dom", "es7"
],
"typeRoots": ["./node_modules/@types/", "./src/typings/"],
"outDir": "./dist",
"sourceMap": true,
"module": "commonjs",
"watch": true,
"moduleResolution": "node",
"allowJs": true,
"isolatedModules": false,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"suppressImplicitAnyIndexErrors": true
},
"include": [
"./src/**/*"
]
}
\ 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