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.
54 lines
1.2 KiB
54 lines
1.2 KiB
5 years ago
|
import {toSnake,toCamel} from '../utils/case'
|
||
|
import * as cronUtils from './cron'
|
||
|
|
||
|
function chatToJson(c) {
|
||
|
const chat = c.dataValues||c
|
||
|
let contactIds = chat.contactIds || null
|
||
|
if(chat.contactIds && typeof chat.contactIds==='string'){
|
||
|
contactIds = JSON.parse(chat.contactIds)
|
||
|
}
|
||
|
return toSnake({
|
||
|
...chat,
|
||
|
contactIds
|
||
|
})
|
||
|
}
|
||
|
|
||
|
function messageToJson(msg, chat = null) {
|
||
|
const message = msg.dataValues||msg
|
||
|
let statusMap = message.statusMap || null
|
||
|
if(message.statusMap && typeof message.statusMap==='string'){
|
||
|
statusMap = JSON.parse(message.statusMap)
|
||
|
}
|
||
|
return toSnake({
|
||
|
...message,
|
||
|
statusMap,
|
||
|
chat: chat ? chatToJson(chat) : null,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
const contactToJson = (contact) => toSnake(contact.dataValues||contact)
|
||
|
|
||
|
const inviteToJson = (invite) => toSnake(invite.dataValues||invite)
|
||
|
|
||
|
const jsonToContact = (json) => toCamel(json)
|
||
|
|
||
|
function subscriptionToJson(subscription, chat) {
|
||
|
const sub = subscription.dataValues || subscription
|
||
|
const { interval, next } = cronUtils.parse(sub.cron)
|
||
|
return toSnake({
|
||
|
...sub,
|
||
|
interval,
|
||
|
next,
|
||
|
chat: chat ? chatToJson(chat) : null,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
export {
|
||
|
messageToJson,
|
||
|
contactToJson,
|
||
|
inviteToJson,
|
||
|
jsonToContact,
|
||
|
chatToJson,
|
||
|
subscriptionToJson,
|
||
|
}
|