Commit 66c67294 authored by qinhaitao's avatar qinhaitao

feat: 🎸 update

parent 551fe6bc
......@@ -8,10 +8,12 @@
"sdkVersion": "*",
"dependencies": {
"dayjs": "^1.8.28",
"get-value": "^3.0.1",
"lodash": "^4.17.20",
"node-xlsx": "^0.15.0",
"set-value": "^3.0.2",
"source-map-support": "^0.5.19",
"taobao-mini-sdk": "^0.2.3"
"taobao-mini-sdk": "^0.2.4"
},
"scripts": {
"start": "tsc",
......@@ -30,7 +32,7 @@
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"prettier": "^2.0.5",
"typescript": "^3.9.7",
"ts-node": "^9.0.0"
"ts-node": "^9.0.0",
"typescript": "^3.9.7"
}
}
/** @format */
import { CODE_TYPES } from './../constants'
import { checkParams, services, registeInfos, preCheck } from '../decorator/common'
import { resultsModel } from '../sdk'
import { TaskService, BaseService } from '../service'
......
/** @format */
import { isEmpty, merge } from 'lodash'
import { isArray, isEmpty, isObject, merge } from 'lodash'
import { UserService } from '../../service'
import { recordErrorLog } from '../../utils/common/logger'
import { resultsModel } from '../../sdk'
import { CODE_TYPES } from '../../errorCode'
import { formatUpdatedUserInfo } from '../../utils/common/format'
import { userInfo } from 'os'
import { formatUpdatedDataByProjection } from '../../utils/common/format'
// 检验参数是否存在
export default function preUpdate(checks: IFunction[]) {
......@@ -31,11 +30,11 @@ export default function preUpdate(checks: IFunction[]) {
otherArgs = { ...otherArgs }
}
console.log(formatUpdatedUserInfo(otherArgs.userInfo, totalUpdateProjection))
// 更新数据
try {
await preUpdateUser(context, otherArgs.userInfo, totalUpdateProjection)
// 避免再次查询
otherArgs.userInfo = formatUpdatedDataByProjection(otherArgs.userInfo, totalUpdateProjection)
} catch (error) {
console.log(error, 'preUpdateUser-error')
recordErrorLog(context, otherArgs, error.toString(), error.stack)
......@@ -47,7 +46,6 @@ export default function preUpdate(checks: IFunction[]) {
}
async function preUpdateUser(context: IContext<IParams>, userInfo: IUserInfo, updateProjection: IPreUpdateQuery) {
return true
// 删除空的操作
if (isEmpty(updateProjection.$inc)) {
delete updateProjection.$inc
......
......@@ -36,7 +36,7 @@ export default class BaseService {
async getItemListByIds(itemIds: string, session: string): Promise<Array<ITaoBaoItems>> {
const GOODSINFO =
'detail_url,approve_status,num_iid,title,nick,type,cid,pic_url,num,props,valid_thru,list_time,desc,price,has_discount,has_invoice,has_warranty,has_showcase,modified,delist_time,postage_id,seller_cids,outer_id,sold_quantity'
const result = await TBAPIS.getItemListByItemIds(this.context, session, itemIds, { fields: GOODSINFO })
const result = await TBAPIS.getItemListByItemIds(this.context, itemIds, { fields: GOODSINFO })
const items = result?.items?.item || []
const list = items.map(
(v: { num_iid: string; title: string; price: string; detail_url: string; pic_url: string; desc: string }) => {
......
......@@ -13,7 +13,7 @@ interface ISuccessResult<T> {
interface ICodeType {
code: string
defaultMsg?: string
defaultMsg: string
}
type IResult<T> = T extends ICodeType ? IErrorResult : IErrorResult | ISuccessResult<T>
......@@ -22,7 +22,7 @@ export default async function checkExchangeCreditsTask(
if (myCredits < credits) return resultsModel.error(CODE_TYPES.ERROR_NO_CREDITS)
// 扣积分
let result = await TBAPIS.changeCredits(context, session, {
let result = await TBAPIS.changeCredits(context, {
quantity: +credits,
change_type: 2, //变更类型:0交易,1:互动活动,2:权益兑换,3:手工调整
opt_type: 1, // 操作类型,'0':增加,1:扣减
......
/** @format */
import { assign, isEmpty, merge } from 'lodash'
import * as set from 'set-value'
import * as get from 'get-value'
/**
* updateUser projection 格式化
......@@ -42,27 +44,28 @@ export function formatUserNick(name: string) {
* @param {IUserInfo} userInfo
* @param {IDecoratorUpdateQuery} projection
*/
export function formatUpdatedUserInfo(userInfo: IUserInfo, projection: IPreUpdateQuery) {
let updatedUserInfo = assign({}, userInfo)
export function formatUpdatedDataByProjection(dbData: object, projection: IPreUpdateQuery) {
let updatedDbData = assign({}, dbData)
if (!isEmpty(projection.$set)) {
updatedUserInfo = merge({}, userInfo, projection.$set)
Object.keys(projection.$set).forEach(key => {
set(updatedDbData, key, projection.$set?.[key])
})
}
if (!isEmpty(projection.$inc)) {
Object.keys(projection.$inc).forEach(key => {
// let splitKey
const originValue = get(updatedDbData, key) || 0
set(updatedDbData, key, projection.$inc?.[key] + originValue)
})
updatedUserInfo = merge({}, userInfo, projection.$set)
updatedDbData = merge({}, dbData, projection.$set)
}
}
function format$Set(userInfo: IUserInfo, setProjection: object) {
Object.keys(setProjection).forEach(setKey => {
const splitKey = setKey.split('.')
let result = {}
splitKey.forEach((key, i) => {
result[key] = i === splitKey.length - 1 ? setProjection[setKey] : {}
if (!isEmpty(projection.$push)) {
Object.keys(projection.$push).forEach(key => {
const originValue = get(updatedDbData, key) || []
set(updatedDbData, key, [...originValue, projection.$push?.[key]])
})
})
}
return updatedDbData
}
......@@ -50,7 +50,7 @@ export const sendTBAward = async (
export const sendCredits = async (credits: number, session: string, context: IContext<IParams>) => {
let drawStatus = 0
let remark = ''
let result = await TBAPIS.changeCredits(context, session, {
let result = await TBAPIS.changeCredits(context, {
quantity: credits,
change_type: 2,
opt_type: '0',
......
......@@ -547,6 +547,13 @@ get-stdin@^6.0.0:
resolved "https://registry.npm.taobao.org/get-stdin/download/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
integrity sha1-ngm/cSs2CrkiXoEgSPcf3pyJZXs=
get-value@^3.0.1:
version "3.0.1"
resolved "https://registry.npm.taobao.org/get-value/download/get-value-3.0.1.tgz#5efd2a157f1d6a516d7524e124ac52d0a39ef5a8"
integrity sha1-Xv0qFX8dalFtdSThJKxS0KOe9ag=
dependencies:
isobject "^3.0.1"
glob-parent@^5.0.0:
version "5.1.1"
resolved "https://registry.npm.taobao.org/glob-parent/download/glob-parent-5.1.1.tgz?cache=0&sync_timestamp=1584836110944&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fglob-parent%2Fdownload%2Fglob-parent-5.1.1.tgz#b6c1ef417c4e5663ea498f1c45afac6916bbc229"
......@@ -631,11 +638,23 @@ is-glob@^4.0.0, is-glob@^4.0.1:
dependencies:
is-extglob "^2.1.1"
is-plain-object@^2.0.4:
version "2.0.4"
resolved "https://registry.npm.taobao.org/is-plain-object/download/is-plain-object-2.0.4.tgz?cache=0&sync_timestamp=1599667338683&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fis-plain-object%2Fdownload%2Fis-plain-object-2.0.4.tgz#2c163b3fafb1b606d9d17928f05c2a1c38e07677"
integrity sha1-LBY7P6+xtgbZ0Xko8FwqHDjgdnc=
dependencies:
isobject "^3.0.1"
isexe@^2.0.0:
version "2.0.0"
resolved "https://registry.npm.taobao.org/isexe/download/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
isobject@^3.0.1:
version "3.0.1"
resolved "https://registry.npm.taobao.org/isobject/download/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8=
js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.npm.taobao.org/js-tokens/download/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
......@@ -804,6 +823,13 @@ semver@^7.2.1, semver@^7.3.2:
resolved "https://registry.npm.taobao.org/semver/download/semver-7.3.2.tgz?cache=0&sync_timestamp=1586886267748&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsemver%2Fdownload%2Fsemver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
integrity sha1-YElisFK4HtB4aq6EOJ/7pw/9OTg=
set-value@^3.0.2:
version "3.0.2"
resolved "https://registry.npm.taobao.org/set-value/download/set-value-3.0.2.tgz#74e8ecd023c33d0f77199d415409a40f21e61b90"
integrity sha1-dOjs0CPDPQ93GZ1BVAmkDyHmG5A=
dependencies:
is-plain-object "^2.0.4"
shebang-command@^2.0.0:
version "2.0.0"
resolved "https://registry.npm.taobao.org/shebang-command/download/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea"
......@@ -902,10 +928,10 @@ table@^5.2.3:
slice-ansi "^2.1.0"
string-width "^3.0.0"
taobao-mini-sdk@^0.2.3:
version "0.2.3"
resolved "https://registry.npm.taobao.org/taobao-mini-sdk/download/taobao-mini-sdk-0.2.3.tgz#5b678fa6d538889301a54f7d5f4ca428cdb3ba6e"
integrity sha1-W2ePptU4iJMBpU99X0ykKM2zum4=
taobao-mini-sdk@^0.2.4:
version "0.2.4"
resolved "https://registry.npm.taobao.org/taobao-mini-sdk/download/taobao-mini-sdk-0.2.4.tgz#5074718bd4135263adbabbf30d8c6b44a0da1d9a"
integrity sha1-UHRxi9QTUmOturvzDYxrRKDaHZo=
dependencies:
"@types/mongodb" "^3.5.26"
......
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