class BaseController { response = (code = 200, msg = '', data = {}, page = 1, limit = 10) => { const res = this.getPagingData(data, page, limit); return { 'errcode': code, 'msg': msg, 'title': msg, // 'data': data, ...res, }; }; getPagination = (page, size = 10) => { const limit = size ? +size : 3; const offset = page ? (page-1) * limit : 0; return { limit, offset }; }; getPagingData = (_data, page, limit) => { const { count: totalCount, rows: data } = _data; if ( !data || !totalCount) { return { data: _data }; } const currentPage = page ? +page : 0; const totalPages = Math.ceil(totalCount / limit); return { totalCount, data, totalPages, currentPage }; }; } module.exports = BaseController;