The Promise process controls the problem that they also need resolve and reject?

  node.js, question
function User(user, mysqlConnection) {
 this.id = user.id;
 this.name = user.name;
 this.phone = user.phone;
 this.password = user.password;
 this.resumeId = user.resumeId;
 
 this.db = mysqlConnection;
 bracket
 
 module.exports = User;
 
 //Store user information
 User.prototype.save = function(callback) {
 var that = this;
 
 var user = {
 name: this.name,
 phone: this.phone,
 password: this.password
 };
 
 //Resume Foreign Key
 if (this.resumeId) user.resumeId = this.resumeId;
 
 //Check if you have registered
 User.get(this.phone, this.db, function(err, result) {
 if (err) {
 callback(err);
 } else {
 if (result.length) {
 //Already Registered
 callback(null, false);
 } else {
 //No write to database registered
 var query = that.db.query('insert into user set ?'  , user, function(err, result) {
 if (err) {
 callback(err);
 } else {
 callback(null, result.insertId);
 bracket
 });
 bracket
 bracket
 });
 };
 
 //Get User Information
 User.get = function(phone, mysqlConnection, callback) {
 var query = mysqlConnection.query('select * from user where phone = ?'  , phone, function(err, result){
 if(err) callback(err);
 callback(null, result);
 });
 };

The above is a prototype-based writing method for user information storage and duplicate checking. Since database operation is involved, it is not very clear to write in callback mode. Therefore, the main problem is to implement such logic when preparing to come to Microsoft&reg in Promise mode:

  1. Firstly, judging whether the user exists or not

  2. In the process of inserting a new user into the database

  3. Return to the main route to render the page

The following wording is wrong, the understanding of Promise is still not in place, please advise.

function Manager(manager, mysqlConnection) {
 this.id = manager.id;
 this.name = manager.name;
 this.phone = manager.phone;
 this.password = manager.password;
 this.companyId = manager.companyId;
 
 this.db = mysqlConnection;
 bracket
 
 var Q = require('q');
 
 module.exports = Manager;
 
 Manager.prototype.save = function() {
 var that = this;
 
 return Q.promise(function(resolve, reject) {
 Manager.get(that.phone, that.db).then(function(data) {
 if (data.length) {
 //The mobile phone number has already been registered
 resolve(false);
 } else {
 var manager = {
 name: that.name,
 phone: that.phone,
 password: that.password
 };
 
 //Resume Foreign Key
 if (that.companyId) manager.companyId = that.companyId;
 
 //No write to database registered
 var query = that.db.query('insert into manager set ?'  , manager, function(err, result) {
 if (err) {
 reject(err);
 } else {
 resolve(result.insertId);
 bracket
 });
 bracket
 });
 });
 };
 
 Manager.get = function(phone, mysqlConnection) {
 return Q.promise(function(resolve, reject) {
 mysqlConnection.query('select * from manager where phone = ?'  , phone, function(err, result) {
 if (err) {
 reject(err);
 } else {
 resolve(result[0]);
 bracket
 });
 });
 bracket
 
 // in main route.js
 var Manager = require('manager.js');
 
 var manager = new Manager({...});
 
 manager.save().then(function(resolve, reject){xxx});
manager.save().then(function(result) {
 
 // do something
 //   ...
 }, function(reason) {
 
 // do something
 //   ...
 });