Commit b2fa8538 authored by Hsinli's avatar Hsinli

add limit page

parent e471087a
Pipeline #14939 passed with stage
in 38 seconds
......@@ -11,6 +11,8 @@ class AbroadHouseController extends Controller {
const { ctx } = this;
let inputParams = ctx.request.body;
const rule = {
page: { type: 'int', required: false },
page_size: { type: 'int', required: false },
name: { type: 'string', required: false },
};
ctx.validate(rule, inputParams);
......
......@@ -70,6 +70,66 @@ module.exports = app => {
tableName: 'abroad_house',
});
AbroadHouse.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await AbroadHouse.findOne({
attributes: attributes,
where: where,
});
}
AbroadHouse.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await AbroadHouse.findAll({
attributes: attributes,
where: where,
order,
});
}
AbroadHouse.list = async (data = {}) => {
const limit = data.limit ? Number(data.limit) : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
const { count, rows } = await AbroadHouse.findAndCountAll(condition);
return { page, count, rows };
}
AbroadHouse.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await AbroadHouse.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
AbroadHouse.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return await AbroadHouse.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return AbroadHouse;
......
......@@ -12,7 +12,11 @@ class AbroadHouseService extends Service {
*/
async abroadHouseList(condition) {
const { ctx } = this;
let page = Number(condition.page) || 1;
let pageSize = Number(condition.page_size) || 10;
let filter = {
page: page,
limit: pageSize,
where: {
valid: 1,
status: 'online',
......@@ -28,7 +32,8 @@ class AbroadHouseService extends Service {
await ctx.service.house.v2.searchHistory.addSearchHistory(addHistory);
filter.where.name = { $like: '%' + condition.name + '%' }
}
let list = await ctx.realestateModel.AbroadHouse.findAll(filter);
let abroadList = await ctx.realestateModel.AbroadHouse.list(filter);
let list = abroadList.rows;
let data = [];
for (let i in list) {
data[i] = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment