Commit 73a67ab8 authored by Hsinli's avatar Hsinli

add

parent e13f3b99
......@@ -21,6 +21,28 @@ class searchHistoryController extends Controller {
}
/**
* 清除搜索记录
*/
async cleanSearchHistory() {
const { ctx } = this;
let inputParams = ctx.params;
const rule = {
type: {
type: 'string',
required: true,
}
};
ctx.validate(rule, inputParams);
if (!['new_house', 'rental_house'].includes(inputParams.type)) {
ctx.failed('error type');
}
let type = inputParams.type === 'new_house' ? 1 : 2;
let ret = await ctx.service.house.searchHistory.cleanSearchHistory(type);
ctx.success(ret);
}
}
module.exports = searchHistoryController;
......@@ -32,6 +32,7 @@ module.exports = app => {
//搜索历史
router.get('/search_history', 'house.searchHistory.getsearchHistory');//收藏列表
router.put('/search_history/:type', 'house.searchHistory.cleanSearchHistory');//用户点击清除搜索记录
//足迹
router.get('/foot_print/list', 'house.footPrint.getFootPrintList');//用户浏览记录列表
......
......@@ -55,11 +55,11 @@ class searchHistoryService extends Service {
value: ctx.userId,
operator: "equal"
},
// {
// key: "createdAt",
// value: endDate,
// operator: "greater"
// },
{
key: "createdAt",
value: endDate,
operator: "greater"
},
],
orderConditions: [{
key: 'createdAt',
......@@ -92,6 +92,54 @@ class searchHistoryService extends Service {
return ret;
}
/**
* 用户点击清除搜索记录
*/
async cleanSearchHistory(type) {
const { ctx, service } = this;
let ret = { status: true };
if (!ctx.appUserId || !ctx.deviceId || !ctx.deviceLoginId || !ctx.userId) {
//如果没有登录就不做处理
return ret;
}
let filter = {
pageIndex: 1,
pageSize: 50,
queryConditions: [{
key: "state",
value: 1,
operator: "equal"
}, {
key: "userId",
value: ctx.userId,
operator: "equal"
}, {
key: "houseStyle",
value: type,
operator: "equal"
}],
orderConditions: [],
}
let searchHistoryList = await service.houseCommon.searchHistory.all(filter);
if (searchHistoryList.rowCount > 0) {
let taskList = [];
for (let i in searchHistoryList.results) {
taskList[i] = service.houseCommon.searchHistory.delete(searchHistoryList.results[i].id);
}
await Promise.all(taskList).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
}
return ret;
}
}
module.exports = searchHistoryService;
......@@ -19,6 +19,36 @@ class SearchHistoryService extends Service {
return result.data;
}
async edit(id, data) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/searchhistory/' + id, data, { method: 'PUT' });
if (result.status !== 200) {
let err = '';
if (typeof (result.data) !== 'string') {
err = JSON.stringify(result.data);
} else {
err = result.data;
}
ctx.failed(err);
}
return result.data;
}
async delete(id) {
const { ctx } = this;
const result = await ctx.helper.send_request(this.config.HOUSE_SERVICE_API + '/v1/searchhistory/' + id, {}, { method: 'DELETE' });
if (result.status !== 200) {
let err = '';
if (typeof (result.data) !== 'string') {
err = JSON.stringify(result.data);
} else {
err = result.data;
}
ctx.failed(err);
}
return result.data;
}
async all(data) {
const { ctx } = this;
const queryConditions = data.queryConditions;
......
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