|
@@ -13,6 +13,10 @@ class NoticeService extends CrudService {
|
|
|
super(ctx, 'notice');
|
|
|
this.model = this.ctx.model.Notice;
|
|
|
this.umodel = this.ctx.model.User;
|
|
|
+ this.stumodel = this.ctx.model.Student;
|
|
|
+ this.schmodel = this.ctx.model.School;
|
|
|
+ this.heamodel = this.ctx.model.Headteacher;
|
|
|
+ this.teamodel = this.ctx.model.Teacher;
|
|
|
}
|
|
|
|
|
|
async create(data) {
|
|
@@ -52,6 +56,39 @@ class NoticeService extends CrudService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async query({ skip, limit, ...info }) {
|
|
|
+ const total = await this.model.count(info);
|
|
|
+ const notices = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
|
|
|
+ const res = [];
|
|
|
+ for (const _notice of notices) {
|
|
|
+ const notice = _.cloneDeep(JSON.parse(JSON.stringify(_notice)));
|
|
|
+ const elm = [];
|
|
|
+ for (const notified of notice.notified) {
|
|
|
+ const _notified = _.cloneDeep(JSON.parse(JSON.stringify(notified)));
|
|
|
+ const user = await this.umodel.findOne({ uid: _notified.notifiedid });
|
|
|
+ const userinfo = await this.findUserInfo(user);
|
|
|
+ console.log({ ...JSON.parse(JSON.stringify(userinfo)), ..._notified });
|
|
|
+ elm.push({ ...JSON.parse(JSON.stringify(userinfo)), ..._notified });
|
|
|
+ }
|
|
|
+ res.push(elm);
|
|
|
+ }
|
|
|
+ return { data: res, total };
|
|
|
+ }
|
|
|
+
|
|
|
+ async findUserInfo(user) {
|
|
|
+ let userinfo;
|
|
|
+ if (user.type === '1') {
|
|
|
+ userinfo = await this.heamodel.findById(user.uid);
|
|
|
+ } else if (user.type === '2') {
|
|
|
+ userinfo = await this.schmodel.findById(user.uid);
|
|
|
+ } else if (user.type === '3') {
|
|
|
+ userinfo = await this.teamodel.findById(user.uid);
|
|
|
+ } else if (user.type === '4') {
|
|
|
+ userinfo = await this.stumodel.findById(user.uid);
|
|
|
+ }
|
|
|
+ return userinfo;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
module.exports = NoticeService;
|