|
@@ -15,9 +15,9 @@ class NoticeService extends CrudService {
|
|
}
|
|
}
|
|
async query({ user_id, ...query }, { skip = 0, limit = 0 } = {}) {
|
|
async query({ user_id, ...query }, { skip = 0, limit = 0 } = {}) {
|
|
const condition = { ...query };
|
|
const condition = { ...query };
|
|
- if (user_id) condition.receive_user = { $elemMatch: { user_id } };
|
|
|
|
|
|
+ if (user_id) condition.receive_user = { $elemMatch: { user_id: ObjectId(user_id) } };
|
|
const data = await this.model.find(condition).skip(parseInt(skip)).limit(parseInt(limit));
|
|
const data = await this.model.find(condition).skip(parseInt(skip)).limit(parseInt(limit));
|
|
- if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
|
|
|
|
|
|
+ if (data.length !== 0) throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
|
|
return data;
|
|
return data;
|
|
}
|
|
}
|
|
async create(body) {
|
|
async create(body) {
|
|
@@ -47,13 +47,11 @@ class NoticeService extends CrudService {
|
|
async updateRead({ id, user_id, status }) {
|
|
async updateRead({ id, user_id, status }) {
|
|
const data = await this.model.findById(id);
|
|
const data = await this.model.findById(id);
|
|
if (!data) throw new BusinessError(ErrorCode.USER_NOT_EXIST);
|
|
if (!data) throw new BusinessError(ErrorCode.USER_NOT_EXIST);
|
|
- const receive_user = [];
|
|
|
|
for (const val of data.receive_user) {
|
|
for (const val of data.receive_user) {
|
|
- if (val.user_id == user_id) val.status = status;
|
|
|
|
- receive_user.push(val);
|
|
|
|
|
|
+ if (ObjectId(val.user_id).equals(user_id)) val.status = status;
|
|
}
|
|
}
|
|
- data.receive_user = receive_user;
|
|
|
|
- await data.save();
|
|
|
|
|
|
+ await this.model.updateOne({ _id: ObjectId(id) }, data);
|
|
|
|
+ return await this.model.findById(id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|