|
@@ -11,6 +11,24 @@ class ScoreService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
super(ctx, 'score');
|
|
|
this.model = this.ctx.model.Score;
|
|
|
+ this.tmodel = this.ctx.model.Teacher;
|
|
|
+ }
|
|
|
+
|
|
|
+ async create(data) {
|
|
|
+ const { teacherid, score } = data;
|
|
|
+ const teacher = await this.tmodel.findById(teacherid);
|
|
|
+ let newscore;
|
|
|
+ if (!teacher.xsscore) {
|
|
|
+ newscore = score;
|
|
|
+ } else {
|
|
|
+ const xsscore = teacher.xsscore;
|
|
|
+ const number = await this.model.count({ teacherid });
|
|
|
+ newscore = (Number(xsscore) * number + Number(score)) / (number + 1);
|
|
|
+
|
|
|
+ }
|
|
|
+ teacher.xsscore = newscore;
|
|
|
+ await teacher.save();
|
|
|
+ return await this.model.create(data);
|
|
|
}
|
|
|
|
|
|
}
|