From b8aabb4cacd3f30dd1968424f537b6a114e1e2cb Mon Sep 17 00:00:00 2001 From: "Xc@centOs" Date: Mon, 30 Jan 2023 21:45:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=8E=E7=BA=A7=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/endpoints/wechat.js | 30 ++++++++++++++++++------------ src/endpoints/wechat.ts | 3 ++- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/endpoints/wechat.js b/lib/endpoints/wechat.js index eccc05ba5..e665b3b8b 100644 --- a/lib/endpoints/wechat.js +++ b/lib/endpoints/wechat.js @@ -114,9 +114,10 @@ function setUserSubscribed(openId, eventKey, context) { // activeAt: now, }; doUpdate = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { - var wechatUser; - return tslib_1.__generator(this, function (_a) { - switch (_a.label) { + var wechatUser, _a, _b, _c; + var _d; + return tslib_1.__generator(this, function (_e) { + switch (_e.label) { case 0: if (!(list && list.length > 0)) return [3 /*break*/, 2]; (0, assert_1.default)(list.length === 1); @@ -134,19 +135,24 @@ function setUserSubscribed(openId, eventKey, context) { id: wechatUser.id, }, }, { dontCollect: true, dontCreateOper: true })]; - case 1: return [2 /*return*/, _a.sent()]; + case 1: return [2 /*return*/, _e.sent()]; case 2: - Object.assign(data, { - subscribed: true, - subscribedAt: now, - applicationId: applicationId, - openId: openId, - }); + _b = (_a = Object).assign; + _c = [data]; + _d = {}; + return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()]; + case 3: + _b.apply(_a, _c.concat([(_d.id = _e.sent(), + _d.subscribed = true, + _d.subscribedAt = now, + _d.applicationId = applicationId, + _d.openId = openId, + _d)])); return [4 /*yield*/, context.operate('wechatUser', { action: 'create', data: data, }, { dontCollect: true })]; - case 3: + case 4: // 这里试着直接把user也创建出来,by Xc 20190720 /** * 这里不能创建user,否则会出现一个weChatUser有openId和userId,却没有unionId @@ -161,7 +167,7 @@ function setUserSubscribed(openId, eventKey, context) { return warden.insertEntity(tables.weChatUser, data, txn); } );*/ - return [2 /*return*/, _a.sent()]; + return [2 /*return*/, _e.sent()]; } }); }); }; diff --git a/src/endpoints/wechat.ts b/src/endpoints/wechat.ts index c001621e8..0e6d120ad 100644 --- a/src/endpoints/wechat.ts +++ b/src/endpoints/wechat.ts @@ -12,7 +12,7 @@ import { EntityDict } from '../general-app-domain'; import { BRC } from '../types/RuntimeCxt'; import { WechatPublicConfig } from '../entities/Application'; import { WechatPublicEventData } from 'oak-external-sdk'; -import { expandUuidTo36Bytes } from 'oak-domain/lib/utils/uuid'; +import { expandUuidTo36Bytes, generateNewIdAsync } from 'oak-domain/lib/utils/uuid'; import { composeDomainUrl } from '../utils/domain'; type VerifyQuery = { @@ -151,6 +151,7 @@ async function setUserSubscribed(openId: string, eventKey: string, context: BRC) } Object.assign(data, { + id: await generateNewIdAsync(), subscribed: true, subscribedAt: now, applicationId,