47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.createWechatLogin = createWechatLogin;
|
|
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
|
async function createWechatLogin(params, context) {
|
|
const { type, interval } = params;
|
|
let userId;
|
|
if (type === 'bind') {
|
|
userId = context.getCurrentUserId();
|
|
}
|
|
const id = await (0, uuid_1.generateNewIdAsync)();
|
|
const createData = {
|
|
id,
|
|
type,
|
|
expiresAt: Date.now() + interval,
|
|
expired: false,
|
|
qrCodeType: 'wechatPublic',
|
|
successed: false,
|
|
};
|
|
if (userId) {
|
|
Object.assign(createData, {
|
|
userId,
|
|
});
|
|
}
|
|
if (type === 'login') {
|
|
const closeRoot = context.openRootMode();
|
|
await context.operate('wechatLogin', {
|
|
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
action: 'create',
|
|
data: createData,
|
|
}, {
|
|
dontCollect: true,
|
|
});
|
|
closeRoot();
|
|
}
|
|
else {
|
|
await context.operate('wechatLogin', {
|
|
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
action: 'create',
|
|
data: createData,
|
|
}, {
|
|
dontCollect: true,
|
|
});
|
|
}
|
|
return id;
|
|
}
|