lrf402788946 hace 5 años
padre
commit
e889a1ae52

+ 3 - 8
app/controller/.chat.js

@@ -1,11 +1,6 @@
 module.exports = {
   create: {
-    requestBody: [
-      "sender_id",
-      "sender_name",
-      "!content",
-      "send_time",
-    ],
+    requestBody: ["sender_id", "sender_name", "!content", "send_time", "role"],
   },
   destroy: {
     params: ["!id"],
@@ -13,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: [ "sender_id", "sender_name", "content", "send_time"],
+    requestBody: ["sender_id", "sender_name", "content", "send_time", "role"],
   },
   show: {
     parameters: {
@@ -23,7 +18,7 @@ module.exports = {
   },
   index: {
     parameters: {
-      query: [ "sender_id", "sender_name", "content", "send_time"],
+      query: ["sender_id", "sender_name", "content", "send_time", "role"],
     },
     service: "query",
     options: {

+ 17 - 2
app/controller/.roomchat.js

@@ -6,6 +6,7 @@ module.exports = {
       "!sender_name",
       "!content",
       "send_time",
+      "role",
     ],
   },
   destroy: {
@@ -14,7 +15,14 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: ["number", "sender_id", "sender_name", "content", "send_time"],
+    requestBody: [
+      "number",
+      "sender_id",
+      "sender_name",
+      "content",
+      "send_time",
+      "role",
+    ],
   },
   show: {
     parameters: {
@@ -24,7 +32,14 @@ module.exports = {
   },
   index: {
     parameters: {
-      query: ["number","sender_id", "sender_name", "content", "send_time"],
+      query: [
+        "number",
+        "sender_id",
+        "sender_name",
+        "content",
+        "send_time",
+        "role",
+      ],
     },
     service: "query",
     options: {

+ 1 - 0
app/model/chat.js

@@ -7,6 +7,7 @@ const Chat = {
   sender_name: { type: String, required: true, maxLength: 200 }, // 发言人名称
   content: { type: String, required: true, maxLength: 1000 }, // 发言内容
   send_time: { type: String, required: true, maxLength: 100 }, // 发言时间:年月日时分秒
+  role: { type: String, maxLength: 200 }, //用户身份
 };
 const schema = new Schema(Chat, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });

+ 1 - 0
app/model/roomchat.js

@@ -8,6 +8,7 @@ const RoomChat = {
   sender_name: { type: String, required: true, maxLength: 200 }, // 发言人名称
   content: { type: String, required: true, maxLength: 1000 }, // 发言内容
   send_time: { type: String, required: true, maxLength: 100 }, // 发言时间:年月日时分秒
+  role: { type: String, maxLength: 200 }, //用户身份
 };
 const schema = new Schema(RoomChat, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });

+ 2 - 2
app/service/chat.js

@@ -11,11 +11,11 @@ class ChatService extends CrudService {
     super(ctx, 'chat');
     this.model = this.ctx.model.Chat;
   }
-  async create(query, { sender_id, sender_name, content }) {
+  async create(query, { sender_id, sender_name, content, role }) {
     assert(sender_name, '缺少发言人信息');
     assert(content, '缺少发言内容');
     const send_time = moment().format('YYYY-MM-DD HH:mm:ss');
-    const res = await this.model.create({ sender_id, sender_name, content, send_time });
+    const res = await this.model.create({ sender_id, sender_name, content, send_time, role });
     // TODO MQ
     const { mq } = this.ctx;
     if (mq) {

+ 2 - 2
app/service/roomchat.js

@@ -13,12 +13,12 @@ class RoomchatService extends CrudService {
     this.model = this.ctx.model.Roomchat;
   }
 
-  async create(query, { number, sender_id, sender_name, content }) {
+  async create(query, { number, sender_id, sender_name, content, role }) {
     assert(sender_name, '缺少发言人信息');
     assert(content, '缺少发言内容');
     assert(number, '缺少房间号');
     const send_time = moment().format('YYYY-MM-DD HH:mm:ss');
-    const res = await this.model.create({ number, sender_id, sender_name, content, send_time });
+    const res = await this.model.create({ number, sender_id, sender_name, content, send_time, role });
     // TODO MQ
     const { mq } = this.ctx;
     if (mq) {