diff --git a/src/controllers/tankersController.js b/src/controllers/tankersController.js index 351e00a4..0a9c2715 100644 --- a/src/controllers/tankersController.js +++ b/src/controllers/tankersController.js @@ -182,7 +182,7 @@ exports.getTankersBookingdetails = async (req, reply) => { const customerId = req.params.customerId const tankerName = req.query.tankerName - await Tankerbooking.find({ customerId:customerId,tankerName: tankerName, } + await Tankerbooking.find({ customerId:customerId,tankerName: tankerName, }) .exec() .then((docs) => { reply.send({ status_code: 200, data: docs, count: docs.length }); diff --git a/src/controllers/userController.js b/src/controllers/userController.js index 309d1239..a147bc89 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -1,6 +1,8 @@ // const fastify = require("fastify")({ // logger: true, // }); + +const axios = require('axios'); const bcrypt = require("bcrypt"); const saltRounds = 10; const libphonenumberjs = require("libphonenumber-js"); @@ -361,7 +363,69 @@ exports.uploadProfilePicture = async (req, reply) => { } }; + + + + +exports.logout = async (request, reply) => { + //console.log(request.headers.authorization) + get_user = await userController.getSingleUser(req) + request.headers.authorization = null + //console.log(request.headers.authorization) + // TODO: Clear any session cookies or authentication tokens + + // Send a success response + reply.send({ message: 'Logout successful' }) + +} + + + + + + + + +// controller.js +const http = require('https'); + +exports.sendSms = async (request, reply) => { + const code = Math.floor(100000 + Math.random() * 900000); + const username = 'Arminta'; + const apiKey = '2068323bea61494d315b'; + const senderId = 'ARMNTA'; + const mobile = request.body.mobileNumbers//'8341426949'; + const message = `Welcome to Arminta !!! your OTP is ${code} please use it for login.`//`Welcome to Arminta !!! your OTP is ${code} please use it for login.`; + + const apiUrl = `https://smslogin.co/v3/api.php?username=${username}&apikey=${apiKey}&senderid=${senderId}&mobile=${mobile}&message=${encodeURIComponent(message)}`; + + const options = { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }; + + const req = http.request(apiUrl, options, (res) => { + let data = ''; + res.on('data', (chunk) => { + data += chunk; + }); + res.on('end', () => { + reply.send(data); + }); + }); + + req.on('error', (error) => { + console.error(error); + reply.send({ error: 'Failed to send SMS' }); + }); + + req.end(); +} + + diff --git a/src/routes/usersRoute.js b/src/routes/usersRoute.js index 11998138..21045178 100644 --- a/src/routes/usersRoute.js +++ b/src/routes/usersRoute.js @@ -250,7 +250,7 @@ module.exports = function (fastify, opts, next) { }, ], }, - // preHandler: [validationHandler.], + //preHandler: [validationHandler], handler: validationHandler.resetPassword, // onResponse: (request,reply) => {validationHandler.resetPassword(request,reply)} }); @@ -413,9 +413,56 @@ module.exports = function (fastify, opts, next) { handler: userController.uploadProfilePicture, }); + + fastify.route({ + method: "DELETE", + url: "/api/logout", + schema: { + tags: ["User"], + description: "This is for logout.", + summary: "This is for logout.", + + security: [ + { + basicAuth: [], + }, + ], + }, + //preHandler: validationHandler.logoutHandler, + handler: userController.logout, + // onResponse: (request,reply) => {validationHandler.resetPassword(request,reply)} + }); + + fastify.route({ + method: "POST", + url: "/api/sendSms", + schema: { + tags: ["User"], + description: "This is to send Sms.", + summary: "This is to send Sms.", + body: { + type: "object", + required: ["mobileNumbers"], + properties: { + mobileNumbers: { type: "string" }, + + }, + }, + security: [ + { + basicAuth: [], + }, + ], + }, + //preHandler: [validationHandler], + handler: userController.sendSms, + // onResponse: (request,reply) => {validationHandler.resetPassword(request,reply)} + }); + + next(); };