You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.8 KiB

5 years ago
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const case_1 = require("../utils/case");
const cronUtils = require("./cron");
function chatToJson(c) {
5 years ago
if (!c)
return {};
const ch = c.dataValues || c;
const chat = JSON.parse(JSON.stringify(ch));
5 years ago
let contactIds = chat.contactIds || null;
if (chat.contactIds && typeof chat.contactIds === 'string') {
contactIds = JSON.parse(chat.contactIds);
}
delete chat.groupPrivateKey;
5 years ago
return case_1.toSnake(Object.assign(Object.assign({}, chat), { contactIds }));
}
exports.chatToJson = chatToJson;
5 years ago
function messageToJson(msg, chat, contact) {
5 years ago
if (!msg)
return {};
5 years ago
const message = msg.dataValues || msg;
let statusMap = message.statusMap || null;
if (message.statusMap && typeof message.statusMap === 'string') {
statusMap = JSON.parse(message.statusMap);
}
5 years ago
return case_1.toSnake(Object.assign(Object.assign({}, message), { statusMap, chat: chat ? chatToJson(chat) : null, contact: contact ? contactToJson(contact) : null }));
5 years ago
}
exports.messageToJson = messageToJson;
5 years ago
function contactToJson(contact) {
if (!contact)
return {};
return case_1.toSnake(contact.dataValues || contact);
}
5 years ago
exports.contactToJson = contactToJson;
const inviteToJson = (invite) => case_1.toSnake(invite.dataValues || invite);
exports.inviteToJson = inviteToJson;
const jsonToContact = (json) => case_1.toCamel(json);
exports.jsonToContact = jsonToContact;
function subscriptionToJson(subscription, chat) {
const sub = subscription.dataValues || subscription;
const { interval, next } = cronUtils.parse(sub.cron);
return case_1.toSnake(Object.assign(Object.assign({}, sub), { interval,
next, chat: chat ? chatToJson(chat) : null }));
}
exports.subscriptionToJson = subscriptionToJson;
//# sourceMappingURL=json.js.map