Commit 9b27f67c authored by 李尚科's avatar 李尚科

realestate model add

parent 31d23be2
Pipeline #7668 passed with stage
in 11 seconds
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const Collection = app.realestateModel.define('collection', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
user_id: {
type: STRING,
allowNull: true
},
app_user_id: {
type: STRING,
allowNull: true
},
connect_id: {
type: INTEGER,
allowNull: true
},
house_style: {
type: INTEGER,
allowNull: true
},
remark: {
type: STRING,
allowNull: true
},
state: {
type: INTEGER,
allowNull: true
},
valid: {
type: INTEGER,
allowNull: true
},
created_at: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
deleted_at: {
type: DATE,
get() {
const date = this.getDataValue('deleted_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'collection',
});
Collection.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Collection.findOne({
attributes: attributes,
where: where,
});
}
Collection.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await Collection.findAll({
attributes: attributes,
where: where,
order,
});
}
Collection.list = async (data = {}) => {
const limit = data.limit ? 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 Collection.findAndCountAll(condition);
return { page, count, rows };
}
Collection.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await Collection.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
Collection.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return res = await Collection.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return Collection;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, ENUM, DATE } = app.Sequelize;
const Developer = app.realestateModel.define('developer', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
address: {
type: STRING,
allowNull: true
},
name: {
type: STRING,
allowNull: true
},
logo: {
type: STRING,
allowNull: true
},
order_id: {
type: INTEGER,
allowNull: true
},
description: {
type: STRING,
allowNull: true
},
status: ENUM('online', 'offline'),
valid: INTEGER,
created_at: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
deleted_at: {
type: DATE,
get() {
const date = this.getDataValue('deleted_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'developer',
});
Developer.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Developer.findOne({
attributes: attributes,
where: where,
});
}
Developer.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await Developer.findAll({
attributes: attributes,
where: where,
order,
});
}
Developer.list = async (data = {}) => {
const limit = data.limit ? 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 Developer.findAndCountAll(condition);
return { page, count, rows };
}
Developer.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await Developer.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
Developer.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return res = await Developer.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return Developer;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const FootPrint = app.realestateModel.define('foot_print', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
user_id: {
type: STRING,
allowNull: true
},
app_user_id: {
type: STRING,
allowNull: true
},
connect_id: {
type: INTEGER,
allowNull: true
},
house_style: {
type: INTEGER,
allowNull: true
},
remark: {
type: STRING,
allowNull: true
},
state: {
type: INTEGER,
allowNull: true
},
valid: {
type: INTEGER,
allowNull: true
},
created_at: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
deleted_at: {
type: DATE,
get() {
const date = this.getDataValue('deleted_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'foot_print',
});
FootPrint.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await FootPrint.findOne({
attributes: attributes,
where: where,
});
}
FootPrint.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await FootPrint.findAll({
attributes: attributes,
where: where,
order,
});
}
FootPrint.list = async (data = {}) => {
const limit = data.limit ? 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 FootPrint.findAndCountAll(condition);
return { page, count, rows };
}
FootPrint.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await FootPrint.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
FootPrint.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return res = await FootPrint.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return FootPrint;
};
...@@ -57,9 +57,11 @@ module.exports = app => { ...@@ -57,9 +57,11 @@ module.exports = app => {
HouseImage.all = async (data) => { HouseImage.all = async (data) => {
const attributes = data.attributes ? data.attributes : {}; const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {}; const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await HouseImage.findAll({ return await HouseImage.findAll({
attributes: attributes, attributes: attributes,
where: where, where: where,
order,
}); });
} }
...@@ -87,17 +89,19 @@ module.exports = app => { ...@@ -87,17 +89,19 @@ module.exports = app => {
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null //从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id; return res.id;
} catch (error) { } catch (error) {
ctx.status = 500;
throw (error); throw (error);
} }
} }
HouseImage.edit = async (data) => { HouseImage.edit = async (data) => {
const where = data.where; const where = data.where;
const params = data.params; const params = data.params;
HouseImage.update(params, { try {
where: where return res = await HouseImage.update(params, { where: where })
}).catch(e => res.json({ status: 500, error: e })); } catch (error) {
throw (error);
}
} }
return HouseImage; return HouseImage;
......
...@@ -168,6 +168,67 @@ module.exports = app => { ...@@ -168,6 +168,67 @@ module.exports = app => {
timestamps: false, timestamps: false,
tableName: 'new_house', tableName: 'new_house',
}); });
NewHouse.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await NewHouse.findOne({
attributes: attributes,
where: where,
});
}
NewHouse.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await NewHouse.findAll({
attributes: attributes,
where: where,
order,
});
}
NewHouse.list = async (data = {}) => {
const limit = data.limit ? 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 NewHouse.findAndCountAll(condition);
return { page, count, rows };
}
NewHouse.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await NewHouse.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
NewHouse.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return res = await NewHouse.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return NewHouse; return NewHouse;
}; };
\ No newline at end of file
...@@ -92,6 +92,67 @@ module.exports = app => { ...@@ -92,6 +92,67 @@ module.exports = app => {
timestamps: false, timestamps: false,
tableName: 'new_house_type', tableName: 'new_house_type',
}); });
NewHouseType.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await NewHouseType.findOne({
attributes: attributes,
where: where,
});
}
NewHouseType.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await NewHouseType.findAll({
attributes: attributes,
where: where,
order,
});
}
NewHouseType.list = async (data = {}) => {
const limit = data.limit ? 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 NewHouseType.findAndCountAll(condition);
return { page, count, rows };
}
NewHouseType.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await NewHouseType.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
NewHouseType.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return res = await NewHouseType.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return NewHouseType; return NewHouseType;
}; };
\ No newline at end of file
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const Order = app.realestateModel.define('order', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
user_id: {
type: STRING,
allowNull: true
},
app_user_id: {
type: STRING,
allowNull: true
},
connect_id: {
type: INTEGER,
allowNull: true
},
house_style: {
type: INTEGER,
allowNull: true
},
remark: {
type: STRING,
allowNull: true
},
name: {
type: STRING,
allowNull: true
},
phone: {
type: STRING,
allowNull: true
},
order_at: {
type: DATE,
get() {
const date = this.getDataValue('order_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
state: {
type: INTEGER,
allowNull: true
},
valid: {
type: INTEGER,
allowNull: true
},
created_at: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
deleted_at: {
type: DATE,
get() {
const date = this.getDataValue('deleted_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'order',
});
Order.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await Order.findOne({
attributes: attributes,
where: where,
});
}
Order.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await Order.findAll({
attributes: attributes,
where: where,
order,
});
}
Order.list = async (data = {}) => {
const limit = data.limit ? 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 Order.findAndCountAll(condition);
return { page, count, rows };
}
Order.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await Order.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
Order.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return res = await Order.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return Order;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const RentalHouse = app.realestateModel.define('rental_house', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
name: {
type: STRING,
allowNull: false
},
residential_id: {
type: INTEGER,
allowNull: true
},
address: {
type: STRING,
allowNull: true
},
price: {
type: DECIMAL,
allowNull: true
},
discount: {
type: DECIMAL,
allowNull: true
},
image: {
type: STRING,
allowNull: true
},
business_license: {
type: STRING,
allowNull: true
},
notice: {
type: STRING,
allowNull: true
},
tags: {
type: STRING,
allowNull: true
},
favourable_info: {
type: STRING,
allowNull: true
},
limit_cities: {
type: STRING,
allowNull: true
},
room_configuration: {
type: STRING,
allowNull: true
},
description: {
type: STRING,
allowNull: true
},
status: {
type: ENUM('offline', 'online'),
allowNull: true
},
valid: {
type: INTEGER,
allowNull: true
},
deleted_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('deleted_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
created_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
}
}, {
timestamps: false,
tableName: 'rental_house',
});
RentalHouse.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await RentalHouse.findOne({
attributes: attributes,
where: where,
});
}
RentalHouse.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await RentalHouse.findAll({
attributes: attributes,
where: where,
order,
});
}
RentalHouse.list = async (data = {}) => {
const limit = data.limit ? 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 RentalHouse.findAndCountAll(condition);
return { page, count, rows };
}
RentalHouse.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await RentalHouse.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
RentalHouse.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return res = await RentalHouse.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return RentalHouse;
};
\ No newline at end of file
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, ENUM } = app.Sequelize;
const RentalHouseType = app.realestateModel.define('rental_house_type', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
name: {
type: STRING,
allowNull: true
},
rental_house_id: {
type: INTEGER,
allowNull: false
},
type: {
type: INTEGER,
allowNull: true
},
price: {
type: DECIMAL,
allowNull: true
},
discount: {
type: DECIMAL,
allowNull: true
},
area: {
type: DECIMAL,
allowNull: true
},
remark: {
type: STRING,
allowNull: true
},
status: {
type: ENUM('online', 'offline'),
allowNull: true
},
valid: {
type: INTEGER,
allowNull: true
},
deleted_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('deleted_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
created_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
}
}, {
timestamps: false,
tableName: 'rental_house_type',
});
RentalHouseType.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await RentalHouseType.findOne({
attributes: attributes,
where: where,
});
}
RentalHouseType.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await RentalHouseType.findAll({
attributes: attributes,
where: where,
order,
});
}
RentalHouseType.list = async (data = {}) => {
const limit = data.limit ? 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 RentalHouseType.findAndCountAll(condition);
return { page, count, rows };
}
RentalHouseType.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await RentalHouseType.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
RentalHouseType.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return res = await RentalHouseType.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return RentalHouseType;
};
\ No newline at end of file
...@@ -67,13 +67,14 @@ module.exports = app => { ...@@ -67,13 +67,14 @@ module.exports = app => {
}); });
} }
Residential.all = async (data) => { Residential.all = async (data) => {
const attributes = data.attributes ? data.attributes : {}; const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {}; const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await Residential.findAll({ return await Residential.findAll({
attributes: attributes, attributes: attributes,
where: where, where: where,
order,
}); });
} }
...@@ -101,7 +102,6 @@ module.exports = app => { ...@@ -101,7 +102,6 @@ module.exports = app => {
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null //从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id; return res.id;
} catch (error) { } catch (error) {
ctx.status = 500;
throw (error); throw (error);
} }
} }
...@@ -109,9 +109,11 @@ module.exports = app => { ...@@ -109,9 +109,11 @@ module.exports = app => {
Residential.edit = async (data) => { Residential.edit = async (data) => {
const where = data.where; const where = data.where;
const params = data.params; const params = data.params;
Residential.update(params, { try {
where: where return res = await Residential.update(params, { where: where })
}).catch(e => res.json({ status: 500, error: e })); } catch (error) {
throw (error);
}
} }
return Residential; return Residential;
......
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, ENUM, DATE } = app.Sequelize;
const ResidentialDeveloper = app.realestateModel.define('residential_developer', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
residential_id: {
type: INTEGER,
allowNull: true
},
developer_id: {
type: INTEGER,
allowNull: true
},
remark: {
type: STRING,
allowNull: true
},
status: {
type: ENUM('online', 'offline'),
allowNull: true
},
valid: {
type: INTEGER,
allowNull: true
},
created_at: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
deleted_at: {
type: DATE,
get() {
const date = this.getDataValue('deleted_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'residential_developer',
});
ResidentialDeveloper.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await ResidentialDeveloper.findOne({
attributes: attributes,
where: where,
});
}
ResidentialDeveloper.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await ResidentialDeveloper.findAll({
attributes: attributes,
where: where,
order,
});
}
ResidentialDeveloper.list = async (data = {}) => {
const limit = data.limit ? 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 ResidentialDeveloper.findAndCountAll(condition);
return { page, count, rows };
}
ResidentialDeveloper.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await ResidentialDeveloper.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
ResidentialDeveloper.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return res = await ResidentialDeveloper.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return ResidentialDeveloper;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, ENUM, DATE } = app.Sequelize;
const SearchHistory = app.realestateModel.define('search_history', {
id: {
type: INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
user_id: {
type: STRING,
allowNull: true
},
app_user_id: {
type: STRING,
allowNull: true
},
key_word: {
type: STRING,
allowNull: true
},
house_style: {
type: INTEGER,
allowNull: true
},
state: {
type: INTEGER,
allowNull: true
},
valid: {
type: INTEGER,
allowNull: true
},
created_at: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
deleted_at: {
type: DATE,
get() {
const date = this.getDataValue('deleted_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'search_history',
});
SearchHistory.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await SearchHistory.findOne({
attributes: attributes,
where: where,
});
}
SearchHistory.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await SearchHistory.findAll({
attributes: attributes,
where: where,
order,
});
}
SearchHistory.list = async (data = {}) => {
const limit = data.limit ? 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 SearchHistory.findAndCountAll(condition);
return { page, count, rows };
}
SearchHistory.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await SearchHistory.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
SearchHistory.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
return res = await SearchHistory.update(params, { where: where })
} catch (error) {
throw (error);
}
}
return SearchHistory;
};
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