customer_id

master
varun 3 years ago
parent b13d2709c7
commit b94c7156f7

@ -9,7 +9,7 @@ const libphonenumberjs = require("libphonenumber-js");
const boom = require("boom"); const boom = require("boom");
// Get Data Models // Get Data Models
const { User,Counter, generateBookingId } = require('../models/User') const { User,Counter, generateBookingId,resetCounter } = require('../models/User')
//const User = require("../models/User"); //const User = require("../models/User");
const customJwtAuth = require("../customAuthJwt"); const customJwtAuth = require("../customAuthJwt");
@ -160,7 +160,7 @@ exports.editCuurentUserInfo = async (req, reply) => {
// Function accepts username, password , encrypts password and saves it in the database. // Function accepts username, password , encrypts password and saves it in the database.
exports.addUser = async (req, reply) => { exports.addUser = async (req, reply) => {
try { try {
// await resetCounter();//to set customer id back to 0
var c_id = await generateBookingId() var c_id = await generateBookingId()
var building= ((req.body.buildingName).slice(0, 3)).toUpperCase(); var building= ((req.body.buildingName).slice(0, 3)).toUpperCase();
var customer_id = `AWS${building}${c_id}` var customer_id = `AWS${building}${c_id}`
@ -263,7 +263,6 @@ exports.loginUser = async (req) => {
const password = req.body.password; const password = req.body.password;
const user = await User.findOne({ phone: phone }); const user = await User.findOne({ phone: phone });
console.log(user.username)
// compare users password with what is supplied // compare users password with what is supplied
if (user) { if (user) {
isSame = await bcryptComparePassword( isSame = await bcryptComparePassword(

@ -16,7 +16,9 @@ const CounterSchema = new mongoose.Schema({
seq: { type: Number, default: 0 } seq: { type: Number, default: 0 }
}); });
const resetCounter = async () => {
await Counter.findOneAndUpdate({ _id: 'booking_id' }, { seq: 0 });
};
const generateBookingId = async () => { const generateBookingId = async () => {
@ -107,4 +109,4 @@ const User = mongoose.model("User", userSchema);
//module.exports = mongoose.model("User", userSchema); //module.exports = mongoose.model("User", userSchema);
module.exports = { User,Counter, generateBookingId }; module.exports = { User,Counter, generateBookingId ,resetCounter};

Loading…
Cancel
Save