|
@@ -10,6 +10,7 @@ class Person_roomService extends CrudService {
|
|
constructor(ctx) {
|
|
constructor(ctx) {
|
|
super(ctx, 'person_room');
|
|
super(ctx, 'person_room');
|
|
this.model = this.ctx.model.PersonRoom;
|
|
this.model = this.ctx.model.PersonRoom;
|
|
|
|
+ this.pc = this.ctx.model.PersonChat;
|
|
}
|
|
}
|
|
async query(query) {
|
|
async query(query) {
|
|
query = this.ctx.service.util.util.turnDateRangeQuery(this.ctx.service.util.util.turnFilter(query));
|
|
query = this.ctx.service.util.util.turnDateRangeQuery(this.ctx.service.util.util.turnFilter(query));
|
|
@@ -18,10 +19,21 @@ class Person_roomService extends CrudService {
|
|
if (p_id) {
|
|
if (p_id) {
|
|
condition.$or = [{ p1_id: p_id }, { p2_id: p_id }];
|
|
condition.$or = [{ p1_id: p_id }, { p2_id: p_id }];
|
|
}
|
|
}
|
|
- console.log(condition);
|
|
|
|
- const data = await this.model.find(condition).skip(parseInt(skip)).limit(parseInt(limit));
|
|
|
|
|
|
+ let data = await this.model.find(condition).skip(parseInt(skip)).limit(parseInt(limit));
|
|
|
|
+ if (data.length > 0) data = JSON.parse(JSON.stringify(data));
|
|
|
|
+ // const notRead = await this.pc.find({ room_id: data.map(i => i._id), is_read: false, receiver_id: p_id });
|
|
|
|
+ const aggQuery = [
|
|
|
|
+ { $match: { room_id: data.map(i => i._id), is_read: false, receiver_id: p_id } },
|
|
|
|
+ {
|
|
|
|
+ $group: {
|
|
|
|
+ _id: '$room_id',
|
|
|
|
+ $sum: 1,
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ ];
|
|
|
|
+ const r = await this.pc.aggregate(aggQuery);
|
|
|
|
+ console.log(r);
|
|
const total = await this.model.count(condition);
|
|
const total = await this.model.count(condition);
|
|
- console.log(total);
|
|
|
|
return { data, total };
|
|
return { data, total };
|
|
}
|
|
}
|
|
async create(payload) {
|
|
async create(payload) {
|