teacher.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const db = require('../config/db');
  2. const getNowFormatTime = require('../util/time-processer');
  3. const Teacher = db.import('../schema/teacher.js');
  4. Teacher.sync();
  5. class TeacherModel {
  6. static async findByUid(uid){
  7. return Teacher.findOne({
  8. where: {uid: uid}
  9. });
  10. }
  11. static async create({realName, organization, jobNumber, certificate = '', id, phone, email} ){
  12. try{
  13. let teacher = await Teacher.create({realName: realName, organization: organization, jobNumber: jobNumber,
  14. phone: phone, email: email, certificate: certificate,
  15. uid: id, createdTime: getNowFormatTime()});
  16. return true;
  17. }catch (e) {
  18. console.log(e);
  19. return false;
  20. }
  21. }
  22. static async updateInfo({realName, organization, jobNumber, certificate = '', uid} ){
  23. try{
  24. await Teacher.update({realName: realName, organization: organization, jobNumber: jobNumber, state: 'identifying'}, {where: {uid: uid}});
  25. return true;
  26. }catch (e) {
  27. console.log(e);
  28. return false;
  29. }
  30. }
  31. static async updateState(id, state){
  32. await Teacher.update({state: state}, {where: {id: id}});
  33. return true;
  34. }
  35. static async getApplications(){
  36. return Teacher.findAll({
  37. where: {state: 'identifying'}
  38. });
  39. }
  40. }
  41. module.exports = TeacherModel;