Files
private-cloud/console/model/stb_operator_dao.js

66 lines
2.0 KiB
JavaScript
Raw Normal View History

/**
* Created by strawmanbobi
* 2016-11-27
*/
// global inclusion
let orm = require('orm');
let dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
let logger = require('../mini_poem/logging/logger4js').helper;
// local inclusion
let ErrorCode = require('../constants/error_code');
let errorCode = new ErrorCode();
let StbOperator = dbOrm.define('stb_operator',
{
id: Number,
operator_id: String,
operator_name: String,
city_code: String,
city_name: String,
status: Number,
operator_name_tw: String
},
{
cache: false
}
);
StbOperator.listStbOperators = function(conditions, from, count, sortField, callback) {
if("id" == sortField && 0 != from) {
conditions.id = orm.lt(from);
StbOperator.find(conditions).limit(parseInt(count)).orderRaw("?? DESC", [sortField])
.run(function (error, stbOperators) {
if (error) {
logger.error("list stbOperators error : " + error);
callback(errorCode.FAILED, null);
} else {
callback(errorCode.SUCCESS, stbOperators);
}
});
} else {
StbOperator.find(conditions).limit(parseInt(count)).offset(parseInt(from)).orderRaw("?? DESC", [sortField])
.run(function (error, stbOperators) {
if (error) {
logger.error("list stbOperators error : " + error);
callback(errorCode.FAILED, null);
} else {
callback(errorCode.SUCCESS, stbOperators);
}
});
}
};
StbOperator.findStbOperatorsByConditions = function(conditions, callback) {
StbOperator.find(conditions, function (error, stbOperators) {
if (error) {
logger.error("find stbOperators error : " + error);
callback(errorCode.FAILED, null);
} else {
callback(errorCode.SUCCESS, stbOperators);
}
});
};
module.exports = StbOperator;