made change in booking id and linked booking data with customer id

master
varun 3 years ago
parent ce014e165c
commit 8dd793c117

@ -1,6 +1,8 @@
const { Tanker, Tankerbooking,Bore,GovtPipeLine } = require('../models/tankers')
const { User,Counter, generateBookingId,resetCounter,generateCustomerId } = require('../models/User')
const User = require("../models/User");
//const User = require("../models/User");
const boom = require("boom");
@ -97,26 +99,25 @@ exports.deleteTankerInfo = async (req, reply) => {
}
};
let bookingCount = 0
exports.tankerBooking = async (req, reply) => {
try {
var customerId = req.params.customerId;
var b_id = await generateBookingId()
const date = new Date()
const year = date.getFullYear()
const month = (date.getMonth() + 1).toString().padStart(2, '0')
const day = date.getDate().toString().padStart(2, '0')
const count = bookingCount.toString().padStart(4, '0')
const bookingId = `ARM${year}${month}${day}${count}`
bookingCount = (bookingCount + 1) % 100;
const bookingId = `ARM${year}${month}${day}${b_id}`
var booking_id = await Tankerbooking.findOne({ bookingid: bookingId})
if(booking_id){
await generateCustomerId()
}
else {
bookingsData = {
customerId:customerId,
bookingid : bookingId,
typeofwater: req.body.typeofwater,
capacity: req.body.capacity,
@ -130,7 +131,8 @@ exports.tankerBooking = async (req, reply) => {
checkFormEncoding = isUserFormUrlEncoded(req);
if (checkFormEncoding.isUserFormUrlEncoded) {
usertobeInserted = checkFormEncoding.tankersBookingData;
console.log("thsi true url string");s
console.log("thsi true url string");
tankersBookingData.customerId = customerId;
tankersBookingData.bookingid = bookingId;
tankersBookingData.capacity = usertobeInserted.capacity;
tankersBookingData.typeofwater = usertobeInserted.typeofwater;

@ -9,7 +9,7 @@ const libphonenumberjs = require("libphonenumber-js");
const boom = require("boom");
// Get Data Models
const { User,Counter, generateBookingId,resetCounter } = require('../models/User')
const { User,Counter, generateBookingId,resetCounter,generateCustomerId } = require('../models/User')
//const User = require("../models/User");
const customJwtAuth = require("../customAuthJwt");
@ -163,7 +163,7 @@ exports.editCuurentUserInfo = async (req, reply) => {
exports.addUser = async (req, reply) => {
try {
// await resetCounter();//to set customer id back to 0
var c_id = await generateBookingId()
var c_id = await generateCustomerId()
var building= ((req.body.buildingName).slice(0, 3)).toUpperCase();
var customer_id = `AWS${building}${c_id}`
// console.log("This is the reply in the handler after the validations", reply);

@ -21,8 +21,18 @@ const resetCounter = async () => {
};
const generateCustomerId = async () => {
var result = await Counter.findOneAndUpdate(
{ _id: 'customer_id' },
{ $inc: { seq: 1 } },
{ upsert: true, new: true }
);
return result.seq;
};
const generateBookingId = async () => {
const result = await Counter.findOneAndUpdate(
var result = await Counter.findOneAndUpdate(
{ _id: 'booking_id' },
{ $inc: { seq: 1 } },
{ upsert: true, new: true }
@ -110,4 +120,4 @@ const User = mongoose.model("User", userSchema);
//module.exports = mongoose.model("User", userSchema);
module.exports = { User,Counter, generateBookingId ,resetCounter};
module.exports = { User,Counter, generateCustomerId,generateBookingId ,resetCounter};

@ -146,11 +146,21 @@ module.exports = function (fastify, opts, next) {
fastify.route({
method: "POST",
url: "/api/bookingData",
url: "/api/bookingData/:customerId",
schema: {
tags: ["Supplier"],
description: "This is for storing booking data of a Tanker",
summary: "This is for storing booking data of a Tanker",
params: {
required: ["customerId"],
type: "object",
properties: {
customerId: {
type: "string",
description: "customerId",
},
},
},
body: {
type: "object",
properties: {

Loading…
Cancel
Save