added bore table in database,removed type in add tanks

master
varun 3 years ago
parent d782833e2b
commit fd1c6b32eb

@ -1,4 +1,4 @@
const { Tanker, Tankerbooking } = require('../models/tankers') const { Tanker, Tankerbooking,Bore } = require('../models/tankers')
const User = require("../models/User"); const User = require("../models/User");
const boom = require("boom"); const boom = require("boom");
@ -166,6 +166,55 @@ exports.getTanker = async (req, reply) => {
console.log(err); console.log(err);
reply.send({ error: err }); reply.send({ error: err });
}); });
} catch (err) {
throw boom.boomify(err);
}
};
exports.addBores = async (req, reply) => {
try {
//const username = req.params.username;
//console.log(req.params);
const username = loginObject.user.username;
//console.log(loginObject.user.username)
// const userInfo = await User.findOne({ username: username.toString() });
// const updateData = req.body;
// console.log("This is the reply in the handler after the validations", reply);
boresData = {
boreName: req.body.boreName,
typeofwater: req.body.typeofwater,
description: req.body.description,
};
var bore_Name = req.body.boreName
var i_bore = await Bore.findOne({ boreName: bore_Name})
if(i_bore){
throw new Error('Bore already exists');
}
else {
var bores = new Bore(boresData);
checkFormEncoding = isUserFormUrlEncoded(req);
if (checkFormEncoding.isUserFormUrlEncoded) {
usertobeInserted = checkFormEncoding.bores;
console.log("thsi true url string");
bores.boreName = usertobeInserted.boreName;
bores.typeofwater = usertobeInserted.typeofwater;
bores.description = usertobeInserted.description;
}
}
const insertedBore = await bores.save();
return insertedBore;
} catch (err) { } catch (err) {
throw boom.boomify(err); throw boom.boomify(err);
} }

@ -26,7 +26,7 @@ console.log(req.params);
blockName: req.body.blockName, blockName: req.body.blockName,
capacity: req.body.capacity, capacity: req.body.capacity,
typeOfWater: req.body.typeOfWater, typeOfWater: req.body.typeOfWater,
type: req.body.type,
tankLocation:req.body.tankLocation, tankLocation:req.body.tankLocation,
}; };
@ -47,7 +47,7 @@ console.log(req.params);
tank.blockName = usertobeInserted.blockName; tank.blockName = usertobeInserted.blockName;
tank.capacity = usertobeInserted.capacity; tank.capacity = usertobeInserted.capacity;
tank.typeOfWater = usertobeInserted.typeOfWater; tank.typeOfWater = usertobeInserted.typeOfWater;
tank.typer = usertobeInserted.type;
tank.tankLocation = usertobeInserted.tankLocation; tank.tankLocation = usertobeInserted.tankLocation;
} }
} }

@ -36,11 +36,21 @@ const tankersbookingSchema = new mongoose.Schema({
}); });
const boreSchema = new mongoose.Schema({
boreName: { type: String, default: null },
typeofwater: { type: String, default: null },
description: { type: String, default: null },
type: { type: String, default: "bore" },
});
const Tanker = mongoose.model("Tanker", tankersSchema); const Tanker = mongoose.model("Tanker", tankersSchema);
const Tankerbooking = mongoose.model("Tankerbooking", tankersbookingSchema); const Tankerbooking = mongoose.model("Tankerbooking", tankersbookingSchema);
const Bore = mongoose.model("Bore", boreSchema);
// Exporting our model objects // Exporting our model objects
module.exports = { module.exports = {
Tanker, Tankerbooking Tanker, Tankerbooking,Bore
} }

@ -15,7 +15,7 @@ const tanksSchema = new mongoose.Schema({
blockName: { type: String, default: null }, blockName: { type: String, default: null },
capacity: { type: String, default: null }, capacity: { type: String, default: null },
typeOfWater: { type: String, default: null }, typeOfWater: { type: String, default: null },
type: { type: String, default: null },
tankLocation: { type: String, default: null }, tankLocation: { type: String, default: null },
connections: { connections: {
source: { type: String}, source: { type: String},

@ -10,9 +10,9 @@ module.exports = function (fastify, opts, next) {
method: "POST", method: "POST",
url: "/api/addTankers", url: "/api/addTankers",
schema: { schema: {
tags: ["Tanker"], tags: ["Supplier"],
description: "This is for cretae New Tanker", description: "This is to cretae New Tanker",
summary: "This is for Create New Tanker.", summary: "This is to Create New Tanker.",
body: { body: {
type: "object", type: "object",
properties: { properties: {
@ -43,8 +43,8 @@ module.exports = function (fastify, opts, next) {
method: "PUT", method: "PUT",
url: "/api/updateTankers/:tankerName", url: "/api/updateTankers/:tankerName",
schema: { schema: {
tags: ["Tanker"], tags: ["Supplier"],
summary: "This is for update tanker", summary: "This is to update tanker",
params: { params: {
required: ["tankerName"], required: ["tankerName"],
type: "object", type: "object",
@ -84,8 +84,8 @@ module.exports = function (fastify, opts, next) {
method: "PUT", method: "PUT",
url: "/api/deleteTanker/:tankerName", url: "/api/deleteTanker/:tankerName",
schema: { schema: {
tags: ["Tanker"], tags: ["Supplier"],
summary: "This is for delete tanker", summary: "This is to delete tanker",
params: { params: {
required: ["tankerName"], required: ["tankerName"],
type: "object", type: "object",
@ -113,7 +113,7 @@ module.exports = function (fastify, opts, next) {
method: "POST", method: "POST",
url: "/api/bookingData", url: "/api/bookingData",
schema: { schema: {
tags: ["Tanker"], tags: ["Supplier"],
description: "This is for storing booking data of a Tanker", description: "This is for storing booking data of a Tanker",
summary: "This is for storing booking data of a Tanker", summary: "This is for storing booking data of a Tanker",
body: { body: {
@ -145,7 +145,7 @@ module.exports = function (fastify, opts, next) {
fastify.get("/api/getTankers", { fastify.get("/api/getTankers", {
schema: { schema: {
tags: ["Tanker"], tags: ["Supplier"],
description: "This is for Get Tanker Data", description: "This is for Get Tanker Data",
summary: "This is for to Get Tanker Data", summary: "This is for to Get Tanker Data",
querystring: { querystring: {
@ -160,6 +160,36 @@ module.exports = function (fastify, opts, next) {
preHandler: fastify.auth([fastify.authenticate]), preHandler: fastify.auth([fastify.authenticate]),
handler: tankersController.getTanker, handler: tankersController.getTanker,
}); });
fastify.route({
method: "POST",
url: "/api/addBores",
schema: {
tags: ["Supplier"],
description: "This is to cretae New Bore",
summary: "This is to Create New Bore.",
body: {
type: "object",
properties: {
boreName: { type: "string" },
typeofwater: { type: "string" },
description: { type: "string" },
},
},
security: [
{
basicAuth: [],
},
],
},
preHandler: fastify.auth([fastify.authenticate]),
handler: tankersController.addBores,
// onResponse: (request, reply) => {
// validationHandler.sendPhoneVerificationCode(request, reply);
// },
//onResponse: validationHandler.sendPhoneVerificationCode,
});

Loading…
Cancel
Save