studentMeetingService.js 1.9 KB
var sutudentMeeting =  require('../model/studentMeetingModel');
var userModel =  require('../model/userModel');
var status = require('../util/resTemplate');
var saitMd5 = require('../util/saltMD5');
var  sequelize = require('../config');
var tokenUtil =  require('../util/tokenUtil');
var meetingModel =  require('../model/meetingModel');
var co = require('co');


function sutudentMeetingService(){

}

sutudentMeetingService.prototype.addStudentMeeting = async(body)=>{
    try {
        var t = await sequelize.transaction({  autocommit: true })     
        let user = await userModel.findOne({where:{id:body.studentId}}); 
        if(!user){
            t.rollback();            
            return {code:300,msg:'用户不存在'}            
        } 
        let oldSutudentMeeting = await sutudentMeeting.findOne({where:{studentId:body.studentId,meetingId:body.meetingId}}); 
        if(oldSutudentMeeting){
            t.rollback();            
            return {code:300,msg:'您已预约这堂课'}            
        } 
        let Meeting = await meetingModel.findOne({where:{id:body.meetingId}}); 
        if(!Meeting){
            t.rollback();            
            return {code:300,msg:'课堂不存在'}            
        }
        let sm = await sutudentMeeting.create(body,{transaction: t});
        // let MeetingBack = await meetingModel.update(
        //     {reservationNumber:Meeting.reservationNumber+1},
        //     {where:{id:body.meetingId}},
        //     {transaction: t});
        t.commit();
        return sm;
    } catch (error) {
        t.rollback();
        throw error;
    }
}

sutudentMeetingService.prototype.getStudentMeetingCount = async(meetingId) =>{
    try {
        let sm = await sutudentMeeting.count({where:{meetingId:meetingId}})
        return sm;
    } catch (error) {
        console.log(error)
        throw error;
    }
}

module.exports = new sutudentMeetingService();