lrf402788946 před 4 roky
rodič
revize
674094401e

+ 36 - 0
app/controller/.answerapply.js

@@ -0,0 +1,36 @@
+module.exports = {
+  create: {
+    requestBody: ["!teacherid", "!date", "!subid"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["!teacherid", "!date", "!subid", "status"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        teacherid: "teacherid",
+        date: "date",
+        subid: "subid",
+        status: "status",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 18 - 0
app/controller/answerapply.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.answerapply.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 教师申请讲课表管理
+class AnswerapplyController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.answerapply;
+  }
+
+}
+
+module.exports = CrudController(AnswerapplyController, meta);

+ 18 - 0
app/model/answerapply.js

@@ -0,0 +1,18 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+const Answerapply = {
+  teacherid: { type: String, required: true, maxLength: 200 }, // 教师id
+  date: { type: [ String ], required: true }, // 申请答疑的时间列表
+  subid: { type: String, required: true, maxLength: 200 }, // 科目id
+  status: { type: String, maxLength: 200, default: '0' }, // 状态:0=>未审核;1=>通过;2=>拒绝
+};
+const schema = new Schema(Answerapply, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Answerapply', schema, 'answerapply');
+};

+ 9 - 2
app/router.js

@@ -544,8 +544,15 @@ module.exports = app => {
     '/api/train/trainvideo/update/:id',
     controller.trainvideo.update
   );
+  // 答疑申请(教师)
+  router.resources('answerapply', '/api/train/answerapply', controller.answerapply); // index、create、show、destroy
+  router.post(
+    'answerapply',
+    '/api/train/answerapply/update/:id',
+    controller.answerapply.update
+  );
   // 答疑房间
-  router.resources('trainvideo', '/api/train/chatroom', controller.chatroom); // index、create、show、destroy
+  router.resources('chatroom', '/api/train/chatroom', controller.chatroom); // index、create、show、destroy
   router.post(
     'chatroom',
     '/api/train/chatroom/update/:id',
@@ -553,7 +560,7 @@ module.exports = app => {
   );
   // 答疑对话
   router.resources(
-    'trainvideo',
+    'answerchat',
     '/api/train/answerchat',
     controller.answerchat
   ); // index、create、show、destroy

+ 41 - 0
app/service/answerapply.js

@@ -0,0 +1,41 @@
+'use strict';
+
+const assert = require('assert');
+const _ = require('lodash');
+const moment = require('moment');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class AnswerapplyService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'answerapply');
+    this.model = this.ctx.model.Answerapply;
+  }
+
+  // async create(data) {
+  //   const { sender_id, sender_name, receiver_id, receiver_name, room, content } = data;
+  //   assert(sender_id, '缺少发送人信息');
+  //   assert(sender_name, '缺少发送人信息');
+  //   assert(receiver_id, '缺少接收人信息');
+  //   assert(receiver_name, '缺少接受人信息');
+  //   assert(room, '缺少房间号');
+  //   assert(content, '缺少发送内容');
+  //   const send_time = moment().format('YYYY-MM-DD HH:mm:ss');
+  //   const res = await this.model.create({ ...data, send_time });
+  //   const { mq } = this.ctx;
+  //   if (mq) {
+  //     const exchange = 'answerchat';
+  //     const parm = {
+  //       durable: true,
+  //       headers: {
+  //         userid: 1,
+  //       } };
+  //     await mq.fanout(exchange, room, JSON.stringify(res), parm);
+  //   }
+  //   return res;
+  // }
+
+}
+
+module.exports = AnswerapplyService;

+ 11 - 0
app/service/student.js

@@ -18,6 +18,17 @@ class StudentService extends CrudService {
     this.gmodel = this.ctx.model.Group;
   }
 
+  async create(data) {
+    const { name, phone: mobile, gender } = data;
+    const res = await this.model.create(data);
+    if (res) {
+      const obj = { name, mobile, gender, type: '4', passwd: '12345678' };
+      const user = await this.ctx.service.user.create(obj);
+    }
+    return res;
+  }
+
+
   // 查询
   async query({ skip, limit, ...info }) {
     const total = await this.model.count(info);