perf(WAI): 不更新写入session id; 部分字段getter

dev/supplier-email-drawer
Lei OT 8 months ago
parent 6c881e1ede
commit 413b554f68

@ -116,7 +116,7 @@ const setupConnectionHandler = () => {
getUserLogger(connectionData.phone).info({ msg: `连接https://web.whatsapp.com/`, connectionData });
// find Or create
await addCurrentConnection({
...objectMapper(connectionData, { phone: [{ key: 'wa_id' }, { key: 'sesson_id' }], channelId: 'channel_id', createTimestamp: 'createtime', version: 'version' }, false),
...objectMapper(connectionData, { phone: [{ key: 'wa_id' }], channelId: 'channel_id', createTimestamp: 'createtime', version: 'version' }, false),
service_type: 'baileys',
status: 'connecting',
});
@ -130,7 +130,7 @@ const setupConnectionHandler = () => {
getUserLogger(connectionData.whatsAppNo).info({ msg: `已登录`, connectionData });
await updateConnection(
{
...objectMapper(connectionData, { whatsAppNo: [{ key: 'wa_id' }, { key: 'sesson_id' }], channelId: 'channel_id' }),
...objectMapper(connectionData, { whatsAppNo: [{ key: 'wa_id' }], channelId: 'channel_id' }),
service_type: 'baileys',
closetime: null,
},
@ -148,7 +148,7 @@ const setupConnectionHandler = () => {
sessionStore.removeSession(connectionData.channelId);
await updateConnection(
{
...objectMapper(connectionData, { whatsAppNo: [{ key: 'wa_id' }, { key: 'sesson_id' }], channelId: 'channel_id' }),
...objectMapper(connectionData, { whatsAppNo: [{ key: 'wa_id' }], channelId: 'channel_id' }),
service_type: 'baileys',
},
{ connect_domain: domain, connect_name: domainName },

@ -20,6 +20,10 @@ module.exports = function(sequelize, DataTypes) {
actionId: {
type: DataTypes.STRING(100),
allowNull: true,
get() {
const rawValue = this.getDataValue('actionId');
return rawValue === null ? '' : rawValue;
},
},
opi_sn: {
type: DataTypes.INTEGER,
@ -71,6 +75,10 @@ module.exports = function(sequelize, DataTypes) {
type: DataTypes.STRING(50),
allowNull: true,
comment: '消息状态 read、send等',
get() {
const rawValue = this.getDataValue('msg_status');
return rawValue === null ? '' : rawValue;
},
},
errors_code: {
type: DataTypes.STRING(50),
@ -132,6 +140,10 @@ module.exports = function(sequelize, DataTypes) {
IVADS_caption: {
type: DataTypes.STRING(1024),
allowNull: true,
get() {
const rawValue = this.getDataValue('IVADS_caption');
return rawValue === null ? '' : rawValue;
},
},
IVADS_id: {
type: DataTypes.STRING(100),
@ -148,6 +160,10 @@ module.exports = function(sequelize, DataTypes) {
IVADS_filename: {
type: DataTypes.TEXT,
allowNull: true,
get() {
const rawValue = this.getDataValue('IVADS_filename');
return rawValue === null ? '' : rawValue;
},
},
location_latitude: {
type: DataTypes.STRING(50),

@ -19,7 +19,7 @@ const addConnection = async data => {
*/
const addCurrentConnection = async data => {
const [r, createdId] = await ConnectionsModel.findOrCreate({
where: { connect_domain: domain, connect_name: name, sesson_id: data.sesson_id },
where: { connect_domain: domain, connect_name: name, wa_id: data.wa_id },
defaults: { ...data, connect_domain: domain, connect_name: name, closetime: null },
});
return r;
@ -30,10 +30,10 @@ const updateConnection = async (data, where = {}) => {
{
...data,
...(data.status === 'open' ? { opentime: Sequelize.fn('NOW') } : {}),
...(data.status === 'close' ? { closetime: Sequelize.fn('NOW') } : {}),
...(['close', 'offline'].includes(data.status) ? { closetime: Sequelize.fn('NOW') } : {}),
updatetime: Sequelize.fn('NOW'),
},
{ where: { ...where, sesson_id: data.sesson_id } },
{ where: { ...where, wa_id: data.wa_id } },
);
return r;
};

Loading…
Cancel
Save