| @@ 1-50 (lines=50) @@ | ||
| 1 | const DB = require('../../libraries/db') |
|
| 2 | const ModelBase = require('../../model/base') |
|
| 3 | const _ = require('underscore') |
|
| 4 | ||
| 5 | const table = 'mist_product' |
|
| 6 | ||
| 7 | module.exports = { |
|
| 8 | add: async function (data) { |
|
| 9 | let res = await ModelBase.execInsert(table, data) |
|
| 10 | return res; |
|
| 11 | }, |
|
| 12 | ||
| 13 | list: async function (storeId, filter) { |
|
| 14 | ||
| 15 | let result = DB.readMysql.select( |
|
| 16 | '*' |
|
| 17 | ) |
|
| 18 | .from(table) |
|
| 19 | .where('store_id', storeId) |
|
| 20 | .whereNot('status', -1) |
|
| 21 | ||
| 22 | if (_.has(filter, 'status')) result.where('status', filter.status) |
|
| 23 | ||
| 24 | if (_.has(filter, 'category_id')) { |
|
| 25 | // todo |
|
| 26 | } |
|
| 27 | ||
| 28 | return await result |
|
| 29 | ||
| 30 | }, |
|
| 31 | ||
| 32 | first: async function (id) { |
|
| 33 | ||
| 34 | let result = DB.readMysql.first( |
|
| 35 | '*' |
|
| 36 | ) |
|
| 37 | .from(table) |
|
| 38 | .where('id', id) |
|
| 39 | ||
| 40 | return await result |
|
| 41 | ||
| 42 | }, |
|
| 43 | ||
| 44 | edit: async function (data, where, notWhere = {}) { |
|
| 45 | let result = ModelBase.execUpdate(table, data, where, notWhere) |
|
| 46 | ||
| 47 | return await result |
|
| 48 | } |
|
| 49 | ||
| 50 | } |
|
| 51 | ||
| @@ 1-50 (lines=50) @@ | ||
| 1 | const DB = require('../../libraries/db') |
|
| 2 | const ModelBase = require('../../model/base') |
|
| 3 | const _ = require('underscore') |
|
| 4 | ||
| 5 | const table = 'mist_category' |
|
| 6 | ||
| 7 | module.exports = { |
|
| 8 | add: async function (data) { |
|
| 9 | let res = await ModelBase.execInsert(table, data) |
|
| 10 | return res; |
|
| 11 | }, |
|
| 12 | ||
| 13 | list: async function (storeId, filter = {}) { |
|
| 14 | ||
| 15 | let result = DB.readMysql.select( |
|
| 16 | '*' |
|
| 17 | ) |
|
| 18 | .from(table) |
|
| 19 | .where('store_id', storeId) |
|
| 20 | .whereNot('status', -1) |
|
| 21 | ||
| 22 | if (_.has(filter, 'status')) result.where('status', filter.status) |
|
| 23 | ||
| 24 | return await result |
|
| 25 | ||
| 26 | }, |
|
| 27 | ||
| 28 | first: async function (id) { |
|
| 29 | ||
| 30 | let result = await DB.readMysql.first( |
|
| 31 | '*' |
|
| 32 | ) |
|
| 33 | .from(table) |
|
| 34 | .where('id', id) |
|
| 35 | ||
| 36 | return result |
|
| 37 | ||
| 38 | }, |
|
| 39 | ||
| 40 | edit: async function (data, where, notWhere = {}) { |
|
| 41 | let result = await ModelBase.execUpdate(table, data, where, notWhere) |
|
| 42 | ||
| 43 | return result |
|
| 44 | }, |
|
| 45 | ||
| 46 | getMaxSort: async function (storeId) { |
|
| 47 | return await DB.readMysql.first('sort').from(table).where({ store_id: storeId }).orderBy('sort', 'DESC') |
|
| 48 | } |
|
| 49 | ||
| 50 | } |
|
| 51 | ||