From b94c7156f7dad862a1d6589299b969cd9d19262e Mon Sep 17 00:00:00 2001 From: varun Date: Mon, 6 Feb 2023 07:14:16 -0500 Subject: [PATCH] customer_id --- src/controllers/userController.js | 5 ++--- src/models/User.js | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/controllers/userController.js b/src/controllers/userController.js index 979e5658..b7f3c9cf 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -9,7 +9,7 @@ const libphonenumberjs = require("libphonenumber-js"); const boom = require("boom"); // Get Data Models -const { User,Counter, generateBookingId } = require('../models/User') +const { User,Counter, generateBookingId,resetCounter } = require('../models/User') //const User = require("../models/User"); 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. exports.addUser = async (req, reply) => { try { - + // await resetCounter();//to set customer id back to 0 var c_id = await generateBookingId() var building= ((req.body.buildingName).slice(0, 3)).toUpperCase(); var customer_id = `AWS${building}${c_id}` @@ -263,7 +263,6 @@ exports.loginUser = async (req) => { const password = req.body.password; const user = await User.findOne({ phone: phone }); - console.log(user.username) // compare users password with what is supplied if (user) { isSame = await bcryptComparePassword( diff --git a/src/models/User.js b/src/models/User.js index ede6d299..86f179ca 100644 --- a/src/models/User.js +++ b/src/models/User.js @@ -16,7 +16,9 @@ const CounterSchema = new mongoose.Schema({ seq: { type: Number, default: 0 } }); - +const resetCounter = async () => { + await Counter.findOneAndUpdate({ _id: 'booking_id' }, { seq: 0 }); +}; const generateBookingId = async () => { @@ -107,4 +109,4 @@ const User = mongoose.model("User", userSchema); //module.exports = mongoose.model("User", userSchema); -module.exports = { User,Counter, generateBookingId }; +module.exports = { User,Counter, generateBookingId ,resetCounter};