parent
c229c947af
commit
bf223c5120
@ -0,0 +1,37 @@
|
||||
const Connections = require("../models/CreateConnections");
|
||||
const User = require("../models/User");
|
||||
const boom = require("boom");
|
||||
const fastify = require("fastify")({
|
||||
logger: true,
|
||||
});
|
||||
|
||||
|
||||
// add new tanks
|
||||
exports.createConnections = async (req, reply) => {
|
||||
try {
|
||||
|
||||
//const username = loginObject.user.username;
|
||||
|
||||
createConnections = {
|
||||
//userName: username,
|
||||
source: req.body.source,
|
||||
inputConnections: req.body.inputConnections,
|
||||
outputConnections:req.body.outputConnections,
|
||||
};
|
||||
|
||||
var connections = new Connections(createConnections);
|
||||
|
||||
checkFormEncoding = isUserFormUrlEncoded(req);
|
||||
if (checkFormEncoding.isUserFormUrlEncoded) {
|
||||
usertobeInserted = checkFormEncoding.connections;
|
||||
connections.source = usertobeInserted.source;
|
||||
connections.inputConnections = req.body.inputConnections;
|
||||
connections.outputConnections = req.body.outputConnections;
|
||||
}
|
||||
const insertedConnection = await connections.save();
|
||||
return insertedConnection;
|
||||
|
||||
} catch (err) {
|
||||
throw boom.boomify(err);
|
||||
}
|
||||
};
|
@ -0,0 +1,20 @@
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
|
||||
|
||||
const Schema = mongoose.Schema;
|
||||
const ObjectId = Schema.Types.ObjectId;
|
||||
|
||||
// Store a random password reset code
|
||||
const code = Math.floor(100000 + Math.random() * 900000);
|
||||
const inputSchema = new Schema({ name: String });
|
||||
const createConnectionsSchema = new mongoose.Schema({
|
||||
|
||||
// userName: { type: String, default: null },
|
||||
source: { type: String,unique:false,trim: true ,required: true},
|
||||
inputConnections: [{ inputConnections: String}],
|
||||
outputConnections: [{ outputConnections: String}]
|
||||
|
||||
});
|
||||
|
||||
module.exports = mongoose.model("Connections", createConnectionsSchema);
|
@ -0,0 +1,56 @@
|
||||
const fastify = require("fastify");
|
||||
const createConnectionController = require("../controllers/createConnectionController");
|
||||
|
||||
module.exports = function (fastify, opts, next) {
|
||||
|
||||
fastify.route({
|
||||
method: "POST",
|
||||
url: "/api/createConnections",
|
||||
schema: {
|
||||
tags: ["Connections"],
|
||||
description: "This is for cretae New Connection",
|
||||
summary: "This is for cretae New Connection.",
|
||||
body: {
|
||||
type: "object",
|
||||
properties: {
|
||||
source: { type: "string" },
|
||||
inputConnections: {
|
||||
type: "array",
|
||||
maxItems: 2,
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
inputConnections: { type: "string", default: null },
|
||||
},
|
||||
},
|
||||
},
|
||||
outputConnections: {
|
||||
type: "array",
|
||||
maxItems: 2,
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
outputConnections: { type: "string", default: null },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
security: [
|
||||
{
|
||||
basicAuth: [],
|
||||
},
|
||||
],
|
||||
|
||||
},
|
||||
preHandler: fastify.auth([fastify.authenticate]),
|
||||
handler: createConnectionController.createConnections,
|
||||
// onResponse: (request, reply) => {
|
||||
// validationHandler.sendPhoneVerificationCode(request, reply);
|
||||
// },
|
||||
//onResponse: validationHandler.sendPhoneVerificationCode,
|
||||
});
|
||||
|
||||
|
||||
next();
|
||||
}
|
Loading…
Reference in new issue