guhongwei 2 năm trước cách đây
mục cha
commit
0c505d4c41
2 tập tin đã thay đổi với 21 bổ sung21 xóa
  1. 15 6
      app/service/channel/channel.js
  2. 6 15
      app/service/consultation/trainLive.js

+ 15 - 6
app/service/channel/channel.js

@@ -9,14 +9,14 @@ const jwt = require('jsonwebtoken');
 // 科技频道
 class ChannelService extends CrudService {
   constructor(ctx) {
-    super(ctx, 'channel');
+    super(ctx, "channel");
     this.model = this.ctx.model.Channel.Channel;
   }
 
   async create(body) {
     const last = await this.model.findOne().sort({ room_id: -1 });
     let room_id = "2001";
-    if (last) room_id = last.room_id + 1;
+    if (last) room_id = parseInt(last.room_id) + 1;
     body.room_id = room_id;
     body.password = { secret: room_id };
     return await this.model.create(body);
@@ -29,11 +29,20 @@ class ChannelService extends CrudService {
    * @property {String} password 密码
    */
   async login({ room_id, password }) {
-    const object = await this.model.findOne({ room_id }, '+password');
-    if (!object) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, `未找到展会号为: ${room_id} 的展会`);
+    const object = await this.model.findOne({ room_id }, "+password");
+    if (!object)
+      throw new BusinessError(
+        ErrorCode.DATA_NOT_EXIST,
+        `未找到展会号为: ${room_id} 的展会`
+      );
     const op = _.get(object, "password.secret");
-    if (!_.isEqual(op, password)) throw new BusinessError(ErrorCode.BAD_PASSWORD, '密码错误');
-    const data = _.omit(JSON.parse(JSON.stringify(object)), [ 'meta', 'password', '__v' ]);
+    if (!_.isEqual(op, password))
+      throw new BusinessError(ErrorCode.BAD_PASSWORD, "密码错误");
+    const data = _.omit(JSON.parse(JSON.stringify(object)), [
+      "meta",
+      "password",
+      "__v",
+    ]);
     const { secret: jwts } = this.config.jwt;
     const token = jwt.sign(data, jwts);
     return token;

+ 6 - 15
app/service/consultation/trainLive.js

@@ -18,7 +18,7 @@ class TrainLiveService extends CrudService {
   async create(body) {
     const last = await this.model.findOne().sort({ room_id: -1 });
     let room_id = "3001";
-    if (last) room_id = last.room_id + 1;
+    if (last) room_id = parseInt(last.room_id) + 1;
     body.room_id = room_id;
     body.password = { secret: room_id };
     return await this.model.create(body);
@@ -31,20 +31,11 @@ class TrainLiveService extends CrudService {
    * @property {String} password 密码
    */
   async login({ room_id, password }) {
-    const object = await this.model.findOne({ room_id }, "+password");
-    if (!object)
-      throw new BusinessError(
-        ErrorCode.DATA_NOT_EXIST,
-        `未找到展会号为: ${room_id} 的展会`
-      );
-    const op = _.get(object, "password.secret");
-    if (!_.isEqual(op, password))
-      throw new BusinessError(ErrorCode.BAD_PASSWORD, "密码错误");
-    const data = _.omit(JSON.parse(JSON.stringify(object)), [
-      "meta",
-      "password",
-      "__v",
-    ]);
+    const object = await this.model.findOne({ room_id }, '+password');
+    if (!object) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, `未找到展会号为: ${room_id} 的展会`);
+    const op = _.get(object, 'password.secret');
+    if (!_.isEqual(op, password)) throw new BusinessError(ErrorCode.BAD_PASSWORD, '密码错误');
+    const data = _.omit(JSON.parse(JSON.stringify(object)), [ 'meta', 'password', '__v' ]);
     const { secret: jwts } = this.config.jwt;
     const token = jwt.sign(data, jwts);
     return token;