UNPKG

umbot

Version:

Universal bot(vk, telegram, viber) or skills for Yandex.Alisa, Маруся and sber

91 lines (90 loc) 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UsersData = void 0; const Model_1 = require("./db/Model"); const mmApp_1 = require("../mmApp"); class UsersData extends Model_1.Model { static TABLE_NAME = 'UsersData'; static T_ALISA = 0; static T_VK = 1; static T_TELEGRAM = 2; static T_VIBER = 3; static T_MARUSIA = 4; static T_SMART_APP = 5; static T_USER_APP = 512; userId; meta; data; type; constructor() { super(); this.userId = null; this.meta = null; this.data = null; this.type = UsersData.T_ALISA; } tableName() { return UsersData.TABLE_NAME; } rules() { return [ { name: ['userId'], type: 'string', max: 250, }, { name: ['meta', 'data'], type: 'text', }, { name: ['type'], type: 'integer', }, ]; } attributeLabels() { return { userId: 'ID', meta: 'User meta data', data: 'User Data', type: 'Type', }; } async getOne() { const query = await this.selectOne(); if (query && query.status) { this.init(this.dbController.getValue(query)); return true; } return false; } validate() { if (mmApp_1.mmApp.isSaveDb) { if (typeof this.meta !== 'string') { this.meta = JSON.stringify(this.meta); } if (typeof this.data !== 'string') { this.data = JSON.stringify(this.data); } } super.validate(); } init(data) { super.init(data); if (mmApp_1.mmApp.isSaveDb) { if (typeof this.meta === 'string') { this.meta = JSON.parse(this.meta); } if (typeof this.data === 'string') { try { this.data = JSON.parse(this.data); } catch (e) { mmApp_1.mmApp.saveLog('userData.log', `Ошибка при парсинге данных: ${e}`); } } } } } exports.UsersData = UsersData;