| + + | +
| + Calendar invitation!! + | +
| + Add To Calendar + | +
|
+ + Kindly use the Calendar Invitation Link above to add to your Calendar + ++ It will expire in 1 day: + + |
+
| + + | +
| + Catch up Event Schedule Notification!! + | +
|
+ + Title: {{ title }} + + |
+
|
+ + Description: {{ description }} + + |
+
|
+ + Location: {{ location }} + + |
+
|
+ + Date: {{ final_event_date }} + + |
+
| + + | +
| + Catch up invitation!! + | +
| + {{ invitationLink }} + | +
|
+ + Kindly use the invitation link above to process your invitation + ++ It will expire in 1 day: + + |
+
Hello
{{ platform.name }} needs this number {{ code }} to verify that you are the one making this request. Please enter the number to continue
- ` + `, }; + +module.exports.sendInvitationLink = { + body: require('./_/sendInvitationLink'), +}; + +module.exports.sendCalendarMail= { + body: require('./_/sendCalendarInvite'), +}; + +module.exports.sendEventScheduleDetails = { + body: require("./_/sendEventDetails"), +} diff --git a/src/services/auth.js b/src/services/auth.js index 11a7c2e..802e3f7 100644 --- a/src/services/auth.js +++ b/src/services/auth.js @@ -1,24 +1,33 @@ const jwt = require('jsonwebtoken'); const asyncHandler = require('express-async-handler'); const { User } = require('../models'); +const axios = require('axios'); +const querystring = require('querystring'); +const { AppError } = require('../utilities'); const signToken = (id) => jwt.sign({ id }, process.env.JWT_SECRET, { expiresIn: process.env.JWT_EXPIRES_IN, }); +const signRefreshToken = (payload) => { + return jwt.sign({ ...payload }, process.env.JWT_SECRET, { + expiresIn: process.env.JWT_EXPIRES_IN, + }); +}; + const createSendToken = (data, status, message, res) => { - let token = ''; + let accessToken = ''; // remove password from output if (data && data.password) { - token = signToken(data._id); + accessToken = signToken(data._id); data.password = null; + data.refreshToken = null; } - return res.json({ status, - token, + accessToken, message, data, }); @@ -70,6 +79,7 @@ const protect = asyncHandler(async (req, res, next) => { token = req.headers.authorization.split(' ')[1]; } + if (!token) { return res.json({ message: 'You are not logged in! Please login to get access', @@ -78,7 +88,6 @@ const protect = asyncHandler(async (req, res, next) => { // validate signToken or verify token const decoded = jwt.verify(token, process.env.JWT_SECRET); - /* check if user still exist (important! especially if the user has been deleted after jwt has been issued) */ const currentUser = await User.findById(decoded.id); if (!currentUser) { @@ -92,9 +101,59 @@ const protect = asyncHandler(async (req, res, next) => { next(); }); + +// Middleware for verifying Google authentication +const requireGoogleAuth = (req, res, next) => { + if (req.isAuthenticated() && req.user) { + next(); + } else { + // Call the next middleware with an error + next(new AppError('Not authenticated with Google',404)); + } +}; + +const createSendData = function sendData(data, status, message, res) { + return res.json({ + status, + message, + data, + }); +}; + +const getTokens = ({ code, clientId, clientSecret, redirectUri }) => { + /* + * Uses the code to get tokens + * that can be used to fetch the user's profile + */ + const url = 'https://oauth2.googleapis.com/token'; + const values = { + code, + client_id: clientId, + client_secret: clientSecret, + redirect_uri: redirectUri, + grant_type: 'authorization_code', + }; + + return axios + .post(url, querystring.stringify(values), { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + }) + .then((res) => res.data) + .catch((error) => { + console.error(`Failed to fetch auth tokens`); + throw new Error(error.message); + }); +}; + module.exports = { createSendToken, protect, generateJWTToken, - googleSendToken + signRefreshToken, + googleSendToken, + createSendData, + getTokens, + requireGoogleAuth }; diff --git a/src/services/calendar.js b/src/services/calendar.js new file mode 100644 index 0000000..4b14e0f --- /dev/null +++ b/src/services/calendar.js @@ -0,0 +1,35 @@ +export function dateTimeForCalander (raw_date) { + + let date = raw_date; + + let year = date.getFullYear(); + let month = date.getMonth() + 1; + if (month < 10) { + month = `0${month}`; + } + let day = date.getDate(); + if (day < 10) { + day = `0${day}`; + } + let hour = date.getHours(); + if (hour < 10) { + hour = `0${hour}`; + } + let minute = date.getMinutes(); + if (minute < 10) { + minute = `0${minute}`; + } + + let newDateTime = `${year}-${month}-${day}T${hour}:${minute}:00.000${TIMEOFFSET}`; + + let event = new Date(Date.parse(newDateTime)); + + let startDate = event; + // Delay in end time is 1 + let endDate = new Date(new Date(startDate).setHours(startDate.getHours()+1)); + + return { + 'start': startDate, + 'end': endDate + } +}; \ No newline at end of file diff --git a/src/services/event.js b/src/services/event.js index 05d0638..e688929 100644 --- a/src/services/event.js +++ b/src/services/event.js @@ -11,7 +11,7 @@ const newEventToken = (data, status, message, res) => { // remove password from output if (data) { - token = signToken(data._id); + token = signToken(data.event._id); } return res.json({ diff --git a/src/services/generateFinalEventDate.js b/src/services/generateFinalEventDate.js new file mode 100644 index 0000000..f86d1bb --- /dev/null +++ b/src/services/generateFinalEventDate.js @@ -0,0 +1,96 @@ +const { Event, ParticipantCount, Participant } = require('../models'); +const { sendEventMail } = require('./Mail/nodemailer'); +const mongoose = require('mongoose'); + +const convertIsoToMiliseconds = (string) => { + let myDate = new Date(string).getTime(); + return `${myDate}`; +}; + +const generateFinalEventDate = async (model, id) => { + const modelData = await model.find({ event_id: id }); + const dateFrequency = {}; + for (let data of modelData) { + const convertedData = convertIsoToMiliseconds(data.preferred_date_time); + if (convertedData in dateFrequency) { + dateFrequency[convertedData] += 1; + } else { + dateFrequency[convertedData] = 1; + } + } + const milliseconds = Object.keys(dateFrequency).reduce((a, b) => + dateFrequency[a] > dateFrequency[b] ? a : b + ); + + const isoDate = new Date(Number(milliseconds)).toISOString(); + return isoDate; +}; + +const generateFinalEventsDates = async () => { + const events = await Event.find(); + for (let event of events) { + const participantCount = await ParticipantCount.findOne({ + event_id: event._id, + }); + if ( + participantCount.participant_count === event.participant_number && + event.published === 'not-decided' && + event.final_event_date === null + ) { + const finalDate = await generateFinalEventDate(Participant, event._id); + const todayDate = new Date(); + todayDate.setHours(0, 0, 0, 0); + const eventFinalDate = new Date(finalDate); + await Event.findByIdAndUpdate( + { _id: event._id }, + { + published: `${todayDate > eventFinalDate ? 'ended' : 'decided'}`, + final_event_date: finalDate, + }, + { + new: true, + runValidators: true, + } + ); + } + } + return; +}; + +const notifyEventParticipants = async (event) => { + let db = mongoose.connection + const participants = await db.collection("participants").find({ event_id: event._id }).toArray(); + if (participants.length > 0) { + for (let participant of participants) { + await sendEventMail(event, participant.email); + } + } +}; + +// const updateEventEndStatus = async ()=>{ +// const events = await Event.find(); +// for (let event of events) { +// const todayDate = new Date(); +// todayDate.setHours(0,0,0,0); +// const eventFinalDate = new Date(event.final_event_date) +// if (todayDate > eventFinalDate){ +// await Event.findByIdAndUpdate( +// { _id: event._id }, +// { +// published: "ended", +// final_event_date: finalDate, +// }, +// { +// new: true, +// runValidators: true, +// } +// ); +// } +// } +// } + +module.exports = { + generateFinalEventDate, + generateFinalEventsDates, + notifyEventParticipants, +}; diff --git a/src/services/index.js b/src/services/index.js index a6509fe..03670c4 100644 --- a/src/services/index.js +++ b/src/services/index.js @@ -1,13 +1,27 @@ -const {createSendToken, protect, googleSendToken} = require("./auth") -const {newParticipantToken, protectParticipant} = require("./participant") -const {newEventToken, protectEvent} = require("./event") +const { + createSendToken, + protect, + googleSendToken, + signRefreshToken, + createSendData, + getTokens +} = require('./auth'); +const { newParticipantToken, protectParticipant } = require('./participant'); +const { newEventToken, protectEvent } = require('./event'); +const generateFinalEventDate = require('./generateFinalEventDate'); +const jwt = require('./jwt.services'); module.exports = { - createSendToken, - protect, - newParticipantToken, - protectParticipant, - newEventToken, - protectEvent, - googleSendToken -} \ No newline at end of file + getTokens, + createSendToken, + protect, + jwt, + signRefreshToken, + newParticipantToken, + protectParticipant, + newEventToken, + protectEvent, + googleSendToken, + generateFinalEventDate, + createSendData, +}; diff --git a/src/services/jwt.services.js b/src/services/jwt.services.js new file mode 100644 index 0000000..3a5ef4c --- /dev/null +++ b/src/services/jwt.services.js @@ -0,0 +1,58 @@ +/* eslint-disable linebreak-style */ +require('dotenv').config(); +const jwt = require('jsonwebtoken'); +const {User} = require('../models'); + +const jwtSecretKey = process.env.JWT_SECRET; +const signToken = (payload) => { + try { + const token = jwt.sign(payload, jwtSecretKey, { expiresIn: '4h' }); + return token; + } catch (error) { + return false; + } +}; +const decodeToken = (token) => { + try { + console.log(token) + const decodedToken = jwt.verify(token, jwtSecretKey); + return decodedToken; + } catch (error) { + return false; + } +}; +const protect = async (req, res, next) => { + try { + const token = req.headers.authorization + ? req.headers.authorization.split(' ')[1] + : null; + if (token == null) { + return res.status(400).json({ message: 'No Token Provided!' }); + } + // decode the token + const decoded = decodeToken(token); + console.log(decoded) + // check if the user exists + const user = await User.findById(decoded.id); + if (!user) { + return res.status(401).json({ + error: 'User Not Found', + }); + } + console.log(`${user.name} is successfully authenticated`); + // add the user to the request + req.user = user; + // call the next middleware + next(); + } catch (error) { + return res.status(401).json({ + status: 'authentication error', + msg: 'sign in to continue', + }); + } +}; +module.exports = { + signToken, + decodeToken, + protect, +}; diff --git a/src/utilities/documentation.js b/src/utilities/documentation.js index 1cf2062..ef56d28 100644 --- a/src/utilities/documentation.js +++ b/src/utilities/documentation.js @@ -1,943 +1,591 @@ -const { signupRouteDoc, loginRouteDoc } = require('../routes/v1/index'); - const swaggerDocumentation = { - "openapi": "3.0.0", - "info": { - "title": "Catchup", - "contact": {}, - "version": "1.0" + "openapi": "3.0.0", + "info": { + "title": "Catchup", + "contact": {}, + "version": "1.0" + }, + "servers": [ + { + "url": "http://api.catchup.hng.tech/api/v1", + "description": "Production Server", + "variables": {} }, - "servers": [ - { - "url": "https://prybar.onrender.com/api/v1", - "description": "production", - "variables": {} - }, - { - "url": "http://localhost:8800/api/v1", - "description": "", - "variables": {} - } - ], - "paths": { - "/auth/signup": { - "post": { - "tags": [ - "auth" - ], - "summary": "signup", - "description": "Registers a new user", - "operationId": "signup", - "parameters": [], - "requestBody": { - "description": "", + { + "url": "http://localhost:8800/api/v1", + "description": "Local Server", + "variables": {} + } + ], + "paths": { + "/event/{id}": { + "get": { + "tags": [ + "Event" + ], + "summary": "Get One Event", + "description": "This returns a single event.", + "operationId": "GetOneEvent", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "Single event id", + "required": true, + "style": "simple", + "schema": { + "type": "string", + "example": "null" + } + } + ], + "responses": { + "200": { + "description": "OK", + "headers": {}, "content": { "application/json": { "schema": { "allOf": [ { - "$ref": "#/components/schemas/signuprequest" + "$ref": "#/components/schemas/GetOneEvent" }, { "example": { - "name": "James Ocee", - "email": "ocjay24@gmail.com", - "password": "catchup123" + "status": "status of the operation", + "token": "data_id token", + "message": "error or success message", + "data": "single event" } } ] }, "example": { - "name": "James Ocee", - "email": "ocjay24@gmail.com", - "password": "catchup123" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "OK", - "headers": { - "Access-Control-Allow-Origin": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "*" - } - } - }, - "Content-Security-Policy": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "default-src 'self';base-uri 'self';block-all-mixed-content;font-src 'self' https: data:;form-action 'self';frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests" - } - } - }, - "Cross-Origin-Embedder-Policy": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "require-corp" - } - } - }, - "Cross-Origin-Opener-Policy": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "same-origin" - } - } - }, - "Cross-Origin-Resource-Policy": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "same-origin" - } - } - }, - "X-DNS-Prefetch-Control": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "off" - } - } - }, - "Expect-CT": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "max-age=0" - } - } - }, - "X-Frame-Options": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "SAMEORIGIN" - } - } - }, - "Strict-Transport-Security": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "max-age=15552000; includeSubDomains" - } - } - }, - "X-Download-Options": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "noopen" - } - } - }, - "X-Content-Type-Options": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "nosniff" - } - } - }, - "Origin-Agent-Cluster": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "?1" - } - } - }, - "X-Permitted-Cross-Domain-Policies": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "none" - } - } - }, - "Referrer-Policy": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "no-referrer" - } - } - }, - "X-XSS-Protection": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "0" - } - } - }, - "X-Powered-By": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "Express" - } - } - }, - "Content-Length": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "82" - } - } - }, - "ETag": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "W/\"52-+hh2O2j0j5m0Fyx/K+T6LyG5CEU\"" - } - } - }, - "Date": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "Sat, 19 Nov 2022 15:35:25 GMT" - } - } - }, - "Connection": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "keep-alive" - } - } - }, - "Keep-Alive": { - "content": { - "text/plain": { - "schema": { - "type": "string" - }, - "example": "timeout=5" - } - } - } - }, - "content": { - "application/json; charset=utf-8": { - "schema": { - "allOf": [ - { - "$ref": "#/components/schemas/example" - }, - { - "example": { - "status": "success", - "token": "", - "message": "Account created successfully", - "data": {} - } - } - ] - }, - "example": { - "status": "success", - "token": "", - "message": "Account created successfully", - "data": {} - } + "status": "status of the operation", + "token": "data_id token", + "message": "error or success message", + "data": "single event" } } } - }, - "deprecated": false, - "security": [] - } + } + }, + "deprecated": false, + "security": [ + { + "bearer": [] + } + ] }, - "/auth/signin": { - "post": { - "tags": [ - "auth" - ], - "summary": "signin", - "description": "Signs in a user", - "operationId": "signin", - "parameters": [], - "requestBody": { - "description": "", + "patch": { + "tags": [ + "Event" + ], + "summary": "Update Event", + "description": "Update a single event.", + "operationId": "UpdateEvent", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "Single event id", + "required": true, + "style": "simple", + "schema": { + "type": "string", + "example": "null" + } + } + ], + "responses": { + "200": { + "description": "OK", + "headers": {}, "content": { "application/json": { "schema": { "allOf": [ { - "$ref": "#/components/schemas/signinrequest" + "$ref": "#/components/schemas/UpdateEvent" }, { "example": { - "email": "ocjay24@gmail.com", - "password": "catchup123" + "status": "status of the operation", + "token": "data_id token", + "message": "success message", + "data": "updated event object" } } ] }, "example": { - "email": "ocjay24@gmail.com", - "password": "catchup123" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "OK", - "headers": {}, - "content": { - "application/json": { - "schema": { - "allOf": [ - { - "$ref": "#/components/schemas/signin" - }, - { - "example": { - "success": true, - "message": "succcess message", - "user": { - "name": "user name", - "id": "user_id", - "email": "user email" - }, - "accessToken": "token" - } - } - ] - }, - "example": { - "success": true, - "message": "Logged in successfully", - "user": { - "name": "user name", - "id": "user_id", - "email": "user email" - }, - "accessToken": "token" - } + "status": "status of the operation", + "token": "data_id token", + "message": "success message", + "data": "updated event object" } } } - }, - "deprecated": false, - "security": [] - } + } + }, + "deprecated": false, + "security": [ + { + "bearer": [] + } + ] }, - "/auth/recover/generate": { - "post": { - "tags": [ - "auth" - ], - "summary": "generate recover token", - "description": "generates a recover token", - "operationId": "generaterecovertoken", - "parameters": [], - "requestBody": { - "description": "", + "delete": { + "tags": [ + "Event" + ], + "summary": "Delete Event", + "description": "An endpoint to delete an event.", + "operationId": "DeleteEvent", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "Single event id", + "required": true, + "style": "simple", + "schema": { + "type": "string", + "example": "null" + } + } + ], + "responses": { + "200": { + "description": "OK", + "headers": {}, "content": { "application/json": { "schema": { "allOf": [ { - "$ref": "#/components/schemas/generaterecovertokenrequest" + "$ref": "#/components/schemas/DeleteEvent" }, { "example": { - "email": "ocjay@gmail.com" + "status": "status of the operation", + "message": "success message", + "data": "deleted event" } } ] }, "example": { - "email": "ocjay@gmail.com" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "OK", - "headers": {}, - "content": { - "application/json": { - "schema": { - "allOf": [ - { - "$ref": "#/components/schemas/generaterecovertoken" - }, - { - "example": { - "status": "success", - "message": "account recovery token has been sent to your email", - "data": { - "account_recovery_token": "account Recovery Token token" - } - } - } - ] - }, - "example": { - "status": "success", - "message": "account recovery token has been sent to your email", - "data": { - "account_recovery_token": "account Recovery Token token" - } - } + "status": "status of the operation", + "message": "success message", + "data": "deleted event" } } } - }, - "deprecated": false, - "security": [] - } - }, - "/auth/recover/confirm": { - "post": { - "tags": [ - "auth" - ], - "summary": "recover account", - "description": "This recovers user account", - "operationId": "recoveraccount", - "parameters": [], - "requestBody": { - "description": "", + } + }, + "deprecated": false, + "security": [ + { + "bearer": [] + } + ] + } + }, + "/event": { + "get": { + "tags": [ + "Event" + ], + "summary": "Get all events", + "description": "Returns all the users events.", + "operationId": "Getallevents", + "parameters": [], + "responses": { + "200": { + "description": "OK", + "headers": {}, "content": { "application/json": { "schema": { "allOf": [ { - "$ref": "#/components/schemas/recoveraccountrequest" + "$ref": "#/components/schemas/Getallevents" }, { "example": { - "token": "access token", - "email": "ocjay24@gmail.com", - "password": "user password" + "status": "status of the operation", + "token": "data_id token", + "message": "error or success message", + "data": "events object" } } ] }, "example": { - "token": "access token", - "email": "ocjay24@gmail.com", - "password": "user password" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "OK", - "headers": {}, - "content": { - "application/json": { - "schema": { - "allOf": [ - { - "$ref": "#/components/schemas/recoveraccount" - }, - { - "example": { - "status": "success", - "message": "account recovered" - } - } - ] - }, - "example": { - "status": "success", - "message": "account recovered" - } + "status": "status of the operation", + "token": "data_id token", + "message": "error or success message", + "data": "events object" } } } - }, - "deprecated": false, - "security": [] - } + } + }, + "deprecated": false, + "security": [ + { + "bearer": [] + } + ] }, - "/auth/refresh": { - "get": { - "tags": [ - "auth" - ], - "summary": "Refresh token", - "description": "This generates a refresh token", - "operationId": "Refreshtoken", - "parameters": [], - "responses": { - "200": { - "description": "OK", - "headers": {}, - "content": { - "application/json": { - "schema": { - "allOf": [ - { - "$ref": "#/components/schemas/Refreshtoken" - }, - { - "example": { - "accessToken": "token" - } - } - ] + "post": { + "tags": [ + "Event" + ], + "summary": "Create event", + "description": "Creates a new event", + "operationId": "Createevent", + "parameters": [], + "requestBody": { + "description": "", + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/CreateeventRequest" }, - "example": { - "accessToken": "token" + { + "example": { + "event_title": "Time out with friends", + "event_description": "A date to have dinner with family and friends", + "location": "Sheraton Hotels", + "event_type": "Dinner", + "participant_number": "5", + "start_date": "25/12/22", + "end_date": "25/12/22", + "host_prefered_time": "7pm" + } } - } + ] + }, + "example": { + "event_title": "Time out with friends", + "event_description": "A date to have dinner with family and friends", + "location": "Sheraton Hotels", + "event_type": "Dinner", + "participant_number": "5", + "start_date": "25/12/22", + "end_date": "25/12/22", + "host_prefered_time": "7pm" } } }, - "deprecated": false, - "security": [] - } - }, - "/event": { - "post": { - "tags": [ - "Event" - ], - "summary": "Create event", - "description": "Creates a new event", - "operationId": "Createevent", - "parameters": [], - "requestBody": { - "description": "", + "required": true + }, + "responses": { + "200": { + "description": "OK", + "headers": {}, "content": { "application/json": { "schema": { "allOf": [ { - "$ref": "#/components/schemas/CreateeventRequest" + "$ref": "#/components/schemas/Createevent" }, { "example": { - "event_title": "Time out with friends", "event_description": "A date to have dinner with family and friends", "location": "Sheraton Hotels", "event_type": "Dinner", "participant_number": "5", "start_date": "25/12/22", "end_date": "25/12/22", - "host_prefered_time": "7pm" + "host_prefered_time": "7pm", + "event_title": "Time out with friends" } } ] }, "example": { - "event_title": "Time out with friends", "event_description": "A date to have dinner with family and friends", "location": "Sheraton Hotels", "event_type": "Dinner", "participant_number": "5", "start_date": "25/12/22", "end_date": "25/12/22", - "host_prefered_time": "7pm" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "OK", - "headers": {}, - "content": { - "application/json": { - "schema": { - "allOf": [ - { - "$ref": "#/components/schemas/Createevent" - }, - { - "example": { - "event_description": "A date to have dinner with family and friends", - "location": "Sheraton Hotels", - "event_type": "Dinner", - "participant_number": "5", - "start_date": "25/12/22", - "end_date": "25/12/22", - "host_prefered_time": "7pm", - "event_title": "Time out with friends" - } - } - ] - }, - "example": { - "event_description": "A date to have dinner with family and friends", - "location": "Sheraton Hotels", - "event_type": "Dinner", - "participant_number": "5", - "start_date": "25/12/22", - "end_date": "25/12/22", - "host_prefered_time": "7pm", - "event_title": "Time out with friends" - } + "host_prefered_time": "7pm", + "event_title": "Time out with friends" } } } - }, - "deprecated": false, - "security": [ - { - "bearer": [] - } - ] + } }, - "get": { - "tags": [ - "Event" - ], - "summary": "Get all events", - "description": "Returns all the users events.", - "operationId": "Getallevents", - "parameters": [], - "responses": { - "200": { - "description": "OK", - "headers": {}, - "content": { - "application/json": { - "schema": { - "allOf": [ - { - "$ref": "#/components/schemas/Getallevents" - }, - { - "example": { - "status": "status of the operation", - "token": "data_id token", - "message": "error or success message", - "data": "events object" - } + "deprecated": false, + "security": [ + { + "bearer": [] + } + ] + } + }, + "/event/token/{id}": { + "get": { + "tags": [ + "Event" + ], + "summary": "Get single Event by Token", + "description": "This endpoint returns a single event by token", + "operationId": "GetsingleEventbyToken", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "Event token id", + "required": true, + "style": "simple", + "schema": { + "type": "string", + "example": "null" + } + } + ], + "responses": { + "200": { + "description": "OK", + "headers": {}, + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/GetsingleEventbyToen" + }, + { + "example": { + "status": "status of the operation", + "token": "data_id token", + "message": "success message", + "data": "single event object" } - ] - }, - "example": { - "status": "status of the operation", - "token": "data_id token", - "message": "error or success message", - "data": "events object" - } + } + ] + }, + "example": { + "status": "status of the operation", + "token": "data_id token", + "message": "success message", + "data": "single event object" } } } - }, - "deprecated": false, - "security": [ - { - "bearer": [] - } - ] - } - }, - "/event/{id}": { - "get": { - "tags": [ - "Event" - ], - "summary": "Get One Event", - "description": "This returns a single event.", - "operationId": "GetOneEvent", - "parameters": [ - { - "name": "id", - "in": "path", - "description": "Single event id", - "required": true, - "style": "simple", - "schema": { - "type": "string", - "example": "null" - } + } + }, + "deprecated": false + } + }, + "/participant/delete/{id}": { + "delete": { + "tags": [ + "Participant" + ], + "summary": "delete Participant", + "description": "Delete a single participant from an event.", + "operationId": "deleteParticipant", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "", + "required": true, + "style": "simple", + "schema": { + "type": "string", + "example": "null" } - ], - "responses": { - "200": { - "description": "OK", - "headers": {}, - "content": { - "application/json": { - "schema": { - "allOf": [ - { - "$ref": "#/components/schemas/GetOneEvent" - }, - { - "example": { - "status": "status of the operation", - "token": "data_id token", - "message": "error or success message", - "data": "single event" - } - } - ] - }, - "example": { - "status": "status of the operation", - "token": "data_id token", - "message": "error or success message", - "data": "single event" - } + } + ], + "responses": { + "200": { + "description": "", + "headers": {}, + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/example" + }, + {} + ] } } } - }, - "deprecated": false, - "security": [ - { - "bearer": [] - } - ] + } }, - "delete": { - "tags": [ - "Event" - ], - "summary": "Delete Event", - "description": "An endpoint to delete an event.", - "operationId": "DeleteEvent", - "parameters": [ - { - "name": "id", - "in": "path", - "description": "Single event id", - "required": true, - "style": "simple", - "schema": { - "type": "string", - "example": "null" - } + "deprecated": false, + "security": [ + { + "bearer": [] + } + ] + } + }, + "/participant/update/{id}": { + "post": { + "tags": [ + "Participant" + ], + "summary": "Update a Participant", + "description": "Update an event's participant.", + "operationId": "UpdateaParticipant", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "", + "required": true, + "style": "simple", + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/example" + }, + {} + ] } - ], - "responses": { - "200": { - "description": "OK", - "headers": {}, - "content": { - "application/json": { - "schema": { - "allOf": [ - { - "$ref": "#/components/schemas/DeleteEvent" - }, - { - "example": { - "status": "status of the operation", - "message": "success message", - "data": "deleted event" - } - } - ] - }, - "example": { - "status": "status of the operation", - "message": "success message", - "data": "deleted event" - } + } + ], + "responses": { + "200": { + "description": "", + "headers": {}, + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/example" + }, + {} + ] } } } - }, - "deprecated": false, - "security": [ - { - "bearer": [] - } - ] + } }, - "patch": { - "tags": [ - "Event" - ], - "summary": "Update Event", - "description": "Update a single event.", - "operationId": "UpdateEvent", - "parameters": [ - { - "name": "id", - "in": "path", - "description": "Single event id", - "required": true, - "style": "simple", + "deprecated": false, + "security": [ + { + "bearer": [] + } + ] + } + }, + "/participant/addpart": { + "post": { + "tags": [ + "Participant" + ], + "summary": "Create Participant", + "description": "Create a new participant for an event.", + "operationId": "CreateParticipant", + "parameters": [], + "requestBody": { + "description": "", + "content": { + "application/json": { "schema": { - "type": "string", - "example": "null" - } - } - ], - "responses": { - "200": { - "description": "OK", - "headers": {}, - "content": { - "application/json": { - "schema": { - "allOf": [ - { - "$ref": "#/components/schemas/UpdateEvent" - }, - { - "example": { - "status": "status of the operation", - "token": "data_id token", - "message": "success message", - "data": "updated event object" - } - } - ] + "allOf": [ + { + "$ref": "#/components/schemas/CreateParticipantRequest" }, - "example": { - "status": "status of the operation", - "token": "data_id token", - "message": "success message", - "data": "updated event object" - } - } + {} + ] } } }, - "deprecated": false, - "security": [ - { - "bearer": [] - } - ] - } - }, - "/event/token/{id}": { - "get": { - "tags": [ - "Event" - ], - "summary": "Get single Event by Token", - "description": "This endpoint returns a single event by token", - "operationId": "GetsingleEventbyToken", - "parameters": [ - { - "name": "id", - "in": "path", - "description": "Event token id", - "required": true, - "style": "simple", - "schema": { - "type": "string", - "example": "null" - } - } - ], - "responses": { - "200": { - "description": "OK", - "headers": {}, - "content": { - "application/json": { - "schema": { - "allOf": [ - { - "$ref": "#/components/schemas/GetsingleEventbyToen" - }, - { - "example": { - "status": "status of the operation", - "token": "data_id token", - "message": "success message", - "data": "single event object" - } - } - ] - }, - "example": { - "status": "status of the operation", - "token": "data_id token", - "message": "success message", - "data": "single event object" - } + "required": true + }, + "responses": { + "200": { + "description": "OK", + "headers": {}, + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/CreateParticipant" + }, + { + "example": { + "fullname": "James Ochapa", + "email": "ocee@catchup.com", + "prefered_date_time": "25/12/2022 4:00" + } + } + ] + }, + "example": { + "fullname": "James Ochapa", + "email": "ocee@catchup.com", + "prefered_date_time": "25/12/2022 4:00" + } + } + } + } + }, + "deprecated": false, + "security": [] + } + }, + "/invitation/": { + "post": { + "tags": [ + "Invite" + ], + "summary": "Create Invite", + "description": "Create a new invite for an event.", + "operationId": "CreateInvite", + "parameters": [], + "requestBody": { + "description": "", + "content": { + "text/plain": { + "schema": { + "type": "object", + "example": { + "email_list": [ + "invitee1@catchup.com", + "invitee2@catchup.com" + ], + "event_id": "input the event's id" } + }, + "example": { + "email_list": [ + "invitee1@catchup.com", + "invitee2@catchup.com" + ], + "event_id": "input the event's id" } } }, - "deprecated": false - } - }, - "/participant/addpart": { - "post": { - "tags": [ - "Participant" - ], - "summary": "Create Participant", - "description": "Create a new participant for an event.", - "operationId": "CreateParticipant", - "parameters": [], - "requestBody": { - "description": "", + "required": true + }, + "responses": { + "200": { + "description": "OK", + "headers": {}, "content": { "application/json": { "schema": { "allOf": [ { - "$ref": "#/components/schemas/CreateParticipantRequest" + "$ref": "#/components/schemas/CreateParticipant" }, { "example": { @@ -954,690 +602,1317 @@ const swaggerDocumentation = { "prefered_date_time": "25/12/2022 4:00" } } - }, - "required": true - }, - "responses": { - "200": { - "description": "OK", - "headers": {}, - "content": { - "application/json": { - "schema": { - "allOf": [ - { - "$ref": "#/components/schemas/CreateParticipant" - }, - { - "example": { - "fullname": "James Ochapa", - "email": "ocee@catchup.com", - "prefered_date_time": "25/12/2022 4:00" - } - } - ] - }, - "example": { - "fullname": "James Ochapa", - "email": "ocee@catchup.com", - "prefered_date_time": "25/12/2022 4:00" - } + } + } + }, + "deprecated": false, + "security": [ + { + "bearer": [] + } + ] + } + }, + "/invitation/{id}": { + "patch": { + "tags": [ + "Invite" + ], + "summary": "Update Invitee", + "description": "This updates a single invite", + "operationId": "UpdateInvitee", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "", + "required": true, + "style": "simple", + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "description": "", + "content": { + "text/plain": { + "schema": { + "type": "object", + "example": { + "email_list": [ + "invitee1@catchup.com", + "invitee2@catchup.com" + ], + "event_id": "input the event's id" } + }, + "example": { + "email_list": [ + "invitee1@catchup.com", + "invitee2@catchup.com" + ], + "event_id": "input the event's id" } } }, - "deprecated": false, - "security": [] - } + "required": true + }, + "responses": { + "200": { + "description": "", + "headers": {}, + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/example" + }, + {} + ] + } + } + } + } + }, + "deprecated": false, + "security": [ + { + "bearer": [] + } + ] }, - "/participant/delete/{id}": { - "delete": { - "tags": [ - "Participant" - ], - "summary": "delete Participant", - "description": "Delete a single participant from an event.", - "operationId": "deleteParticipant", - "parameters": [ - { - "name": "id", - "in": "path", - "description": "", - "required": true, - "style": "simple", + "delete": { + "tags": [ + "Invite" + ], + "summary": "Delete invite", + "description": "This endpoint removes an invite.", + "operationId": "Deleteinvite", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "", + "required": true, + "style": "simple", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "", + "headers": {}, + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/example" + }, + {} + ] + } + } + } + } + }, + "deprecated": false, + "security": [ + { + "bearer": [] + } + ] + } + }, + "/auth/signin": { + "post": { + "tags": [ + "Auth" + ], + "summary": "signin", + "description": "Signs in a user", + "operationId": "signin", + "parameters": [], + "requestBody": { + "description": "", + "content": { + "application/json": { "schema": { - "type": "string", - "example": "null" + "allOf": [ + { + "$ref": "#/components/schemas/signinrequest" + }, + { + "example": { + "email": "ocjay24@gmail.com", + "password": "catchup123" + } + } + ] + }, + "example": { + "email": "ocjay24@gmail.com", + "password": "catchup123" } } - ], - "responses": { - "200": { - "description": "", - "headers": {} + }, + "required": true + }, + "responses": { + "200": { + "description": "OK", + "headers": {}, + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/signin" + }, + { + "example": { + "success": true, + "message": "Logged in successfully", + "user": { + "name": "user name", + "id": "user_id", + "email": "user email" + }, + "accessToken": "token" + } + } + ] + }, + "example": { + "success": true, + "message": "Logged in successfully", + "user": { + "name": "user name", + "id": "user_id", + "email": "user email" + }, + "accessToken": "token" + } + } + } + } + }, + "deprecated": false, + "security": [] + } + }, + "/auth/signup": { + "post": { + "tags": [ + "Auth" + ], + "summary": "signup", + "description": "Registers a new user", + "operationId": "signup", + "parameters": [], + "requestBody": { + "description": "", + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/signuprequest" + }, + { + "example": { + "name": "James Ocee", + "email": "ocjay24@gmail.com", + "password": "catchup123" + } + } + ] + }, + "example": { + "name": "James Ocee", + "email": "ocjay24@gmail.com", + "password": "catchup123" + } } }, - "deprecated": false, - "security": [ - { - "bearer": [] + "required": true + }, + "responses": { + "200": { + "description": "OK", + "headers": { + "Access-Control-Allow-Origin": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "*" + } + } + }, + "Content-Security-Policy": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "default-src 'self';base-uri 'self';block-all-mixed-content;font-src 'self' https: data:;form-action 'self';frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests" + } + } + }, + "Cross-Origin-Embedder-Policy": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "require-corp" + } + } + }, + "Cross-Origin-Opener-Policy": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "same-origin" + } + } + }, + "Cross-Origin-Resource-Policy": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "same-origin" + } + } + }, + "X-DNS-Prefetch-Control": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "off" + } + } + }, + "Expect-CT": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "max-age=0" + } + } + }, + "X-Frame-Options": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "SAMEORIGIN" + } + } + }, + "Strict-Transport-Security": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "max-age=15552000; includeSubDomains" + } + } + }, + "X-Download-Options": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "noopen" + } + } + }, + "X-Content-Type-Options": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "nosniff" + } + } + }, + "Origin-Agent-Cluster": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "?1" + } + } + }, + "X-Permitted-Cross-Domain-Policies": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "none" + } + } + }, + "Referrer-Policy": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "no-referrer" + } + } + }, + "X-XSS-Protection": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "0" + } + } + }, + "X-Powered-By": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "Express" + } + } + }, + "Content-Length": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "82" + } + } + }, + "ETag": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "W/\"52-+hh2O2j0j5m0Fyx/K+T6LyG5CEU\"" + } + } + }, + "Date": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "Sat, 19 Nov 2022 15:35:25 GMT" + } + } + }, + "Connection": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "keep-alive" + } + } + }, + "Keep-Alive": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "timeout=5" + } + } + } + }, + "content": { + "application/json; charset=utf-8": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/example" + }, + { + "example": { + "status": "success", + "token": "", + "message": "Account created successfully", + "data": {} + } + } + ] + }, + "example": { + "status": "success", + "token": "", + "message": "Account created successfully", + "data": {} + } + } } - ] - } - }, - "/participant/update/{id}": { - "patch": { - "tags": [ - "Participant" - ], - "summary": "Get One Participant", - "description": "Update an event's participant.", - "operationId": "GetOneParticipant", - "parameters": [ - { - "name": "id", - "in": "path", - "description": "", - "required": true, - "style": "simple", + } + }, + "deprecated": false, + "security": [] + } + }, + "/auth/recover/confirm": { + "post": { + "tags": [ + "Auth" + ], + "summary": "recover account", + "description": "This recovers user account", + "operationId": "recoveraccount", + "parameters": [], + "requestBody": { + "description": "", + "content": { + "application/json": { "schema": { - "type": "string", - "example": "null" + "allOf": [ + { + "$ref": "#/components/schemas/recoveraccountrequest" + }, + { + "example": { + "token": "access token", + "email": "ocjay24@gmail.com", + "password": "user password" + } + } + ] + }, + "example": { + "token": "access token", + "email": "ocjay24@gmail.com", + "password": "user password" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "OK", + "headers": {}, + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/recoveraccount" + }, + { + "example": { + "status": "success", + "message": "account recovered" + } + } + ] + }, + "example": { + "status": "success", + "message": "account recovered" + } } } - ], - "responses": { - "200": { - "description": "", - "headers": {} + } + }, + "deprecated": false, + "security": [] + } + }, + "/auth/recover/generate": { + "post": { + "tags": [ + "Auth" + ], + "summary": "generate recover token", + "description": "generates a recover token", + "operationId": "generaterecovertoken", + "parameters": [], + "requestBody": { + "description": "", + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/generaterecovertokenrequest" + }, + { + "example": { + "email": "ocjay@gmail.com" + } + } + ] + }, + "example": { + "email": "ocjay@gmail.com" + } } }, - "deprecated": false, - "security": [ - { - "bearer": [] + "required": true + }, + "responses": { + "200": { + "description": "OK", + "headers": {}, + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/generaterecovertoken" + }, + { + "example": { + "status": "success", + "message": "account recovery token has been sent to your email", + "data": { + "account_recovery_token": "account Recovery Token token" + } + } + } + ] + }, + "example": { + "status": "success", + "message": "account recovery token has been sent to your email", + "data": { + "account_recovery_token": "account Recovery Token token" + } + } + } } - ] - } + } + }, + "deprecated": false, + "security": [] } }, - "components": { - "schemas": { - "signuprequest": { - "title": "signuprequest", - "required": [ - "name", - "email", - "password" - ], - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "email": { - "type": "string" - }, - "password": { - "type": "string" + "/auth/refresh": { + "get": { + "tags": [ + "Auth" + ], + "summary": "Refresh token", + "description": "This generates a refresh token", + "operationId": "Refreshtoken", + "parameters": [], + "responses": { + "200": { + "description": "OK", + "headers": {}, + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/Refreshtoken" + }, + { + "example": { + "accessToken": "token" + } + } + ] + }, + "example": { + "accessToken": "token" + } + } + } + } + }, + "deprecated": false, + "security": [] + } + }, + "/auth/google/url": { + "get": { + "tags": [ + "Auth" + ], + "summary": "Get google login url", + "description": "This loads the google auth interface where the user selects his account", + "operationId": "Getgoogleloginurl", + "parameters": [], + "responses": { + "200": { + "description": "", + "headers": {}, + "content": { + "text/plain": { + "schema": { + "type": "string", + "example": "Returns google authentication url" + }, + "example": "Returns google authentication url" + } + } + } + }, + "deprecated": false, + "security": [] + } + }, + "/auth/google": { + "get": { + "tags": [ + "Auth" + ], + "summary": "Get user google auth", + "description": "Authenticate a user from google", + "operationId": "Getusergoogleauth", + "parameters": [], + "responses": { + "200": { + "description": "", + "headers": {}, + "content": { + "text/plain": { + "schema": { + "type": "object", + "example": { + "status": "request status", + "token": "signed token", + "message": "message", + "data": "access_token" + } + }, + "example": { + "status": "request status", + "token": "signed token", + "message": "message", + "data": "access_token" + } + } } - }, - "example": { - "name": "James Ocee", - "email": "ocjay24@gmail.com", - "password": "catchup123" } }, - "example": { - "title": "example", - "required": [ - "status", - "token", - "message", - "data" - ], - "type": "object", - "properties": { - "status": { - "type": "string" - }, - "token": { - "type": "string" - }, - "message": { - "type": "string" - }, - "data": { - "type": "object" - } + "deprecated": false, + "security": [] + } + } + }, + "components": { + "schemas": { + "generaterecovertoken": { + "title": "generaterecovertoken", + "required": [ + "status", + "message", + "data" + ], + "type": "object", + "properties": { + "status": { + "type": "string" }, - "example": { - "status": "success", - "token": "", - "message": "Account created successfully", - "data": {} + "message": { + "type": "string" + }, + "data": { + "allOf": [ + { + "$ref": "#/components/schemas/Data" + }, + {} + ] } }, - "signinrequest": { - "title": "signinrequest", - "required": [ - "email", - "password" - ], - "type": "object", - "properties": { - "email": { - "type": "string" - }, - "password": { - "type": "string" - } + "example": { + "status": "success", + "message": "account recovery token has been sent to your email", + "data": { + "account_recovery_token": "account Recovery Token token" + } + } + }, + "example": { + "title": "example", + "required": [ + "status", + "token", + "message", + "data" + ], + "type": "object", + "properties": { + "status": { + "type": "string" + }, + "token": { + "type": "string" }, - "example": { - "email": "ocjay24@gmail.com", - "password": "catchup123" + "message": { + "type": "string" + }, + "data": { + "type": "object" } }, - "signin": { - "title": "signin", - "required": [ - "success", - "message", - "user", - "accessToken" - ], - "type": "object", - "properties": { - "success": { - "type": "boolean" - }, - "message": { - "type": "string" - }, - "user": { - "allOf": [ - { - "$ref": "#/components/schemas/User" - }, - {} - ] - }, - "accessToken": { - "type": "string" - } + "example": { + "status": "success", + "token": "", + "message": "Account created successfully", + "data": {} + } + }, + "recoveraccount": { + "title": "recoveraccount", + "required": [ + "status", + "message" + ], + "type": "object", + "properties": { + "status": { + "type": "string" }, - "example": { - "success": true, - "message": "Logged in successfully", - "user": { - "name": "user name", - "id": "user_id", - "email": "user email" - }, - "accessToken": "token" + "message": { + "type": "string" } }, - "User": { - "title": "User", - "required": [ - "name", - "id", - "email" - ], - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "id": { - "type": "string" - }, - "email": { - "type": "string" - } + "example": { + "status": "success", + "message": "account recovered" + } + }, + "Createevent": { + "title": "Createevent", + "required": [ + "event_description", + "location", + "event_type", + "participant_number", + "start_date", + "end_date", + "host_prefered_time", + "event_title" + ], + "type": "object", + "properties": { + "event_description": { + "type": "string" }, - "example": { - "name": "user name", - "id": "user_id", - "email": "user email" + "location": { + "type": "string" + }, + "event_type": { + "type": "string" + }, + "participant_number": { + "type": "string" + }, + "start_date": { + "type": "string" + }, + "end_date": { + "type": "string" + }, + "host_prefered_time": { + "type": "string" + }, + "event_title": { + "type": "string" } }, - "generaterecovertokenrequest": { - "title": "generaterecovertokenrequest", - "required": [ - "email" - ], - "type": "object", - "properties": { - "email": { - "type": "string" - } + "example": { + "event_description": "A date to have dinner with family and friends", + "location": "Sheraton Hotels", + "event_type": "Dinner", + "participant_number": "5", + "start_date": "25/12/22", + "end_date": "25/12/22", + "host_prefered_time": "7pm", + "event_title": "Time out with friends" + } + }, + "DeleteEvent": { + "title": "DeleteEvent", + "required": [ + "status", + "message", + "data" + ], + "type": "object", + "properties": { + "status": { + "type": "string" + }, + "message": { + "type": "string" }, - "example": { - "email": "ocjay@gmail.com" + "data": { + "type": "string" } }, - "generaterecovertoken": { - "title": "generaterecovertoken", - "required": [ - "status", - "message", - "data" - ], - "type": "object", - "properties": { - "status": { - "type": "string" - }, - "message": { - "type": "string" - }, - "data": { - "allOf": [ - { - "$ref": "#/components/schemas/Data" - }, - {} - ] - } + "example": { + "status": "status of the operation", + "message": "success message", + "data": "deleted event" + } + }, + "signinrequest": { + "title": "signinrequest", + "required": [ + "email", + "password" + ], + "type": "object", + "properties": { + "email": { + "type": "string" }, - "example": { - "status": "success", - "message": "account recovery token has been sent to your email", - "data": { - "account_recovery_token": "account Recovery Token token" - } + "password": { + "type": "string" } }, - "Data": { - "title": "Data", - "required": [ - "account_recovery_token" - ], - "type": "object", - "properties": { - "account_recovery_token": { - "type": "string" - } + "example": { + "email": "ocjay24@gmail.com", + "password": "catchup123" + } + }, + "Getallevents": { + "title": "Getallevents", + "required": [ + "status", + "token", + "message", + "data" + ], + "type": "object", + "properties": { + "status": { + "type": "string" }, - "example": { - "account_recovery_token": "account Recovery Token token" + "token": { + "type": "string" + }, + "message": { + "type": "string" + }, + "data": { + "type": "string" } }, - "recoveraccountrequest": { - "title": "recoveraccountrequest", - "required": [ - "token", - "email", - "password" - ], - "type": "object", - "properties": { - "token": { - "type": "string" - }, - "email": { - "type": "string" - }, - "password": { - "type": "string" - } + "example": { + "status": "status of the operation", + "token": "data_id token", + "message": "error or success message", + "data": "events object" + } + }, + "UpdateEvent": { + "title": "UpdateEvent", + "required": [ + "status", + "token", + "message", + "data" + ], + "type": "object", + "properties": { + "status": { + "type": "string" + }, + "token": { + "type": "string" }, - "example": { - "token": "access token", - "email": "ocjay24@gmail.com", - "password": "user password" + "message": { + "type": "string" + }, + "data": { + "type": "string" } }, - "recoveraccount": { - "title": "recoveraccount", - "required": [ - "status", - "message" - ], - "type": "object", - "properties": { - "status": { - "type": "string" - }, - "message": { - "type": "string" - } + "example": { + "status": "status of the operation", + "token": "data_id token", + "message": "success message", + "data": "updated event object" + } + }, + "signuprequest": { + "title": "signuprequest", + "required": [ + "name", + "email", + "password" + ], + "type": "object", + "properties": { + "name": { + "type": "string" }, - "example": { - "status": "success", - "message": "account recovered" + "email": { + "type": "string" + }, + "password": { + "type": "string" } }, - "Refreshtoken": { - "title": "Refreshtoken", - "required": [ - "accessToken" - ], - "type": "object", - "properties": { - "accessToken": { - "type": "string" - } + "example": { + "name": "James Ocee", + "email": "ocjay24@gmail.com", + "password": "catchup123" + } + }, + "signin": { + "title": "signin", + "required": [ + "success", + "message", + "user", + "accessToken" + ], + "type": "object", + "properties": { + "success": { + "type": "boolean" }, - "example": { - "accessToken": "token" + "message": { + "type": "string" + }, + "user": { + "allOf": [ + { + "$ref": "#/components/schemas/User" + }, + {} + ] + }, + "accessToken": { + "type": "string" } }, - "CreateeventRequest": { - "title": "CreateeventRequest", - "required": [ - "event_title", - "event_description", - "location", - "event_type", - "participant_number", - "start_date", - "end_date", - "host_prefered_time" - ], - "type": "object", - "properties": { - "event_title": { - "type": "string" - }, - "event_description": { - "type": "string" - }, - "location": { - "type": "string" - }, - "event_type": { - "type": "string" - }, - "participant_number": { - "type": "string" - }, - "start_date": { - "type": "string" - }, - "end_date": { - "type": "string" - }, - "host_prefered_time": { - "type": "string" - } + "example": { + "success": true, + "message": "Logged in successfully", + "user": { + "name": "user name", + "id": "user_id", + "email": "user email" + }, + "accessToken": "token" + } + }, + "User": { + "title": "User", + "required": [ + "name", + "id", + "email" + ], + "type": "object", + "properties": { + "name": { + "type": "string" }, - "example": { - "event_title": "Time out with friends", - "event_description": "A date to have dinner with family and friends", - "location": "Sheraton Hotels", - "event_type": "Dinner", - "participant_number": "5", - "start_date": "25/12/22", - "end_date": "25/12/22", - "host_prefered_time": "7pm" + "id": { + "type": "string" + }, + "email": { + "type": "string" } }, - "Createevent": { - "title": "Createevent", - "required": [ - "event_description", - "location", - "event_type", - "participant_number", - "start_date", - "end_date", - "host_prefered_time", - "event_title" - ], - "type": "object", - "properties": { - "event_description": { - "type": "string" - }, - "location": { - "type": "string" - }, - "event_type": { - "type": "string" - }, - "participant_number": { - "type": "string" - }, - "start_date": { - "type": "string" - }, - "end_date": { - "type": "string" - }, - "host_prefered_time": { - "type": "string" - }, - "event_title": { - "type": "string" - } - }, - "example": { - "event_description": "A date to have dinner with family and friends", - "location": "Sheraton Hotels", - "event_type": "Dinner", - "participant_number": "5", - "start_date": "25/12/22", - "end_date": "25/12/22", - "host_prefered_time": "7pm", - "event_title": "Time out with friends" + "example": { + "name": "user name", + "id": "user_id", + "email": "user email" + } + }, + "Refreshtoken": { + "title": "Refreshtoken", + "required": [ + "accessToken" + ], + "type": "object", + "properties": { + "accessToken": { + "type": "string" } }, - "Getallevents": { - "title": "Getallevents", - "required": [ - "status", - "token", - "message", - "data" - ], - "type": "object", - "properties": { - "status": { - "type": "string" - }, - "token": { - "type": "string" - }, - "message": { - "type": "string" - }, - "data": { - "type": "string" - } + "example": { + "accessToken": "token" + } + }, + "CreateeventRequest": { + "title": "CreateeventRequest", + "required": [ + "event_title", + "event_description", + "location", + "event_type", + "participant_number", + "start_date", + "end_date", + "host_prefered_time" + ], + "type": "object", + "properties": { + "event_title": { + "type": "string" + }, + "event_description": { + "type": "string" + }, + "location": { + "type": "string" }, - "example": { - "status": "status of the operation", - "token": "data_id token", - "message": "error or success message", - "data": "events object" + "event_type": { + "type": "string" + }, + "participant_number": { + "type": "string" + }, + "start_date": { + "type": "string" + }, + "end_date": { + "type": "string" + }, + "host_prefered_time": { + "type": "string" } }, - "GetOneEvent": { - "title": "GetOneEvent", - "required": [ - "status", - "token", - "message", - "data" - ], - "type": "object", - "properties": { - "status": { - "type": "string" - }, - "token": { - "type": "string" - }, - "message": { - "type": "string" - }, - "data": { - "type": "string" - } + "example": { + "event_title": "Time out with friends", + "event_description": "A date to have dinner with family and friends", + "location": "Sheraton Hotels", + "event_type": "Dinner", + "participant_number": "5", + "start_date": "25/12/22", + "end_date": "25/12/22", + "host_prefered_time": "7pm" + } + }, + "GetOneEvent": { + "title": "GetOneEvent", + "required": [ + "status", + "token", + "message", + "data" + ], + "type": "object", + "properties": { + "status": { + "type": "string" + }, + "token": { + "type": "string" }, - "example": { - "status": "status of the operation", - "token": "data_id token", - "message": "error or success message", - "data": "single event" + "message": { + "type": "string" + }, + "data": { + "type": "string" } }, - "GetsingleEventbyToen": { - "title": "GetsingleEventbyToen", - "required": [ - "status", - "token", - "message", - "data" - ], - "type": "object", - "properties": { - "status": { - "type": "string" - }, - "token": { - "type": "string" - }, - "message": { - "type": "string" - }, - "data": { - "type": "string" - } + "example": { + "status": "status of the operation", + "token": "data_id token", + "message": "error or success message", + "data": "single event" + } + }, + "GetsingleEventbyToen": { + "title": "GetsingleEventbyToen", + "required": [ + "status", + "token", + "message", + "data" + ], + "type": "object", + "properties": { + "status": { + "type": "string" }, - "example": { - "status": "status of the operation", - "token": "data_id token", - "message": "success message", - "data": "single event object" + "token": { + "type": "string" + }, + "message": { + "type": "string" + }, + "data": { + "type": "string" } }, - "DeleteEvent": { - "title": "DeleteEvent", - "required": [ - "status", - "message", - "data" - ], - "type": "object", - "properties": { - "status": { - "type": "string" - }, - "message": { - "type": "string" - }, - "data": { - "type": "string" - } + "example": { + "status": "status of the operation", + "token": "data_id token", + "message": "success message", + "data": "single event object" + } + }, + "CreateParticipantRequest": { + "title": "CreateParticipantRequest", + "required": [ + "fullname", + "email", + "prefered_date_time" + ], + "type": "object", + "properties": { + "fullname": { + "type": "string" + }, + "email": { + "type": "string" }, - "example": { - "status": "status of the operation", - "message": "success message", - "data": "deleted event" + "prefered_date_time": { + "type": "string" } }, - "UpdateEvent": { - "title": "UpdateEvent", - "required": [ - "status", - "token", - "message", - "data" - ], - "type": "object", - "properties": { - "status": { - "type": "string" - }, - "token": { - "type": "string" - }, - "message": { - "type": "string" - }, - "data": { - "type": "string" - } - }, - "example": { - "status": "status of the operation", - "token": "data_id token", - "message": "success message", - "data": "updated event object" + "example": { + "fullname": "James Ochapa", + "email": "ocee@catchup.com", + "prefered_date_time": "25/12/2022 4:00" + } + }, + "generaterecovertokenrequest": { + "title": "generaterecovertokenrequest", + "required": [ + "email" + ], + "type": "object", + "properties": { + "email": { + "type": "string" } }, - "CreateParticipantRequest": { - "title": "CreateParticipantRequest", - "required": [ - "fullname", - "email", - "prefered_date_time" - ], - "type": "object", - "properties": { - "fullname": { - "type": "string" - }, - "email": { - "type": "string" - }, - "prefered_date_time": { - "type": "string" - } - }, - "example": { - "fullname": "James Ochapa", - "email": "ocee@catchup.com", - "prefered_date_time": "25/12/2022 4:00" + "example": { + "email": "ocjay@gmail.com" + } + }, + "Data": { + "title": "Data", + "required": [ + "account_recovery_token" + ], + "type": "object", + "properties": { + "account_recovery_token": { + "type": "string" } }, - "CreateParticipant": { - "title": "CreateParticipant", - "required": [ - "fullname", - "email", - "prefered_date_time" - ], - "type": "object", - "properties": { - "fullname": { - "type": "string" - }, - "email": { - "type": "string" - }, - "prefered_date_time": { - "type": "string" - } + "example": { + "account_recovery_token": "account Recovery Token token" + } + }, + "recoveraccountrequest": { + "title": "recoveraccountrequest", + "required": [ + "token", + "email", + "password" + ], + "type": "object", + "properties": { + "token": { + "type": "string" + }, + "email": { + "type": "string" }, - "example": { - "fullname": "James Ochapa", - "email": "ocee@catchup.com", - "prefered_date_time": "25/12/2022 4:00" + "password": { + "type": "string" } + }, + "example": { + "token": "access token", + "email": "ocjay24@gmail.com", + "password": "user password" } }, - "securitySchemes": { - "bearer": { - "type": "http", - "scheme": "bearer" + "CreateParticipant": { + "title": "CreateParticipant", + "required": [ + "fullname", + "email", + "prefered_date_time" + ], + "type": "object", + "properties": { + "fullname": { + "type": "string" + }, + "email": { + "type": "string" + }, + "prefered_date_time": { + "type": "string" + } + }, + "example": { + "fullname": "James Ochapa", + "email": "ocee@catchup.com", + "prefered_date_time": "25/12/2022 4:00" } } }, - "security": [], - "tags": [ - { - "name": "auth" - }, - { - "name": "Event" - }, - { - "name": "Participant" + "securitySchemes": { + "bearer": { + "type": "http", + "scheme": "bearer" } - ] - } + } + }, + "security": [], + "tags": [ + { + "name": "Auth" + }, + { + "name": "Event" + }, + { + "name": "Participant" + }, + { + "name": "Invite", + "description": "" + } + ] +} + + + + module.exports = swaggerDocumentation; \ No newline at end of file diff --git a/src/validators/createEvent.js b/src/validators/createEvent.js index 446f839..0057b5c 100644 --- a/src/validators/createEvent.js +++ b/src/validators/createEvent.js @@ -2,7 +2,6 @@ const Joi = require('joi'); const createEventSchema = Joi.object({ event_title: Joi.string() - .pattern(/^[A-Za-z][A-Za-z ]{2,30}$/) .trim() .min(3) .max(150) diff --git a/src/validators/createParticipant.js b/src/validators/createParticipant.js index 97f6264..ebd9d76 100644 --- a/src/validators/createParticipant.js +++ b/src/validators/createParticipant.js @@ -1,19 +1,20 @@ const Joi = require('joi'); +Joi.objectId = require('joi-objectid')(Joi); const createParticipantSchema = Joi.object({ - fullname: Joi.string() + fullname: Joi.string() .pattern(/^[A-Za-z][A-Za-z ]{2,30}$/) .min(3) .max(30) .required(), - email: Joi.string() + email: Joi.string() .email({ tlds: { allow: false } }) .required(), - // participant_id: Joi.object(), + event_id: Joi.objectId(), - prefered_date_time: Joi.date().required(), + preferred_date_time: Joi.string().required(), }); module.exports = createParticipantSchema; diff --git a/src/validators/createUser.js b/src/validators/createUser.js index 98cd721..20c9acc 100644 --- a/src/validators/createUser.js +++ b/src/validators/createUser.js @@ -2,20 +2,18 @@ const Joi = require('joi'); const createUserSchema = Joi.object({ name: Joi.string() - .pattern(/^[A-Za-z][A-Za-z ]{2,30}$/) - .min(3) - .max(30) - .required(), + .min(3) + .max(30) + .required(), +email: Joi.string() + .email({ tlds: { allow: false } }) + .required(), +password: Joi.string() + .min(8) + .max(30) + .pattern(new RegExp('^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!@#$%^&*()_+\\-=\\[\\]{};:\\\\|,.<>\\/?])(?=.{8,30})')) + .required() - email: Joi.string() - .email({ tlds: { allow: false } }) - .required(), - - password: Joi.string() - .pattern(/^\w[a-zA-Z0-9]{8,30}$/) - .min(8) - .max(30) - .required(), }); module.exports = createUserSchema; diff --git a/src/validators/index.js b/src/validators/index.js index 2ff38ef..0f7030b 100644 --- a/src/validators/index.js +++ b/src/validators/index.js @@ -1,8 +1,15 @@ -const createUserSchema = require("./createUser") -const createParticipantSchema = require("./createParticipant"); -const loginUserSchema = require("./loginUser") -const createEventSchema = require("./createEvent") +const createUserSchema = require('./createUser'); +const createParticipantSchema = require('./createParticipant'); +const loginUserSchema = require('./loginUser'); +const createEventSchema = require('./createEvent'); +const updatedUserSchema = require('./updateUser'); +const recoverPasswordSchema = require('./recoverPassword'); module.exports = { -createUserSchema, createParticipantSchema,createEventSchema,loginUserSchema -} \ No newline at end of file + createUserSchema, + createParticipantSchema, + createEventSchema, + loginUserSchema, + updatedUserSchema, + recoverPasswordSchema, +}; diff --git a/src/validators/loginUser.js b/src/validators/loginUser.js index 9dab137..c406c02 100644 --- a/src/validators/loginUser.js +++ b/src/validators/loginUser.js @@ -6,9 +6,9 @@ const loginUserSchema = Joi.object({ .required(), password: Joi.string() - .pattern(/^\w[a-zA-Z0-9]{8,30}$/) .min(8) .max(30) + .pattern(new RegExp('^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!@#$%^&*()_+\\-=\\[\\]{};:\\\\|,.<>\\/?])(?=.{8,30})')) .required(), }); diff --git a/src/validators/recoverPassword.js b/src/validators/recoverPassword.js new file mode 100644 index 0000000..17472b9 --- /dev/null +++ b/src/validators/recoverPassword.js @@ -0,0 +1,16 @@ +const Joi = require('joi'); + +const recoverPasswordSchema = Joi.object({ + email: Joi.string() + .email({ tlds: { allow: false } }) + .required(), + + password: Joi.string() + .pattern(/^\w[a-zA-Z0-9]{8,30}$/) + .min(8) + .max(30) + .required(), + token: Joi.string().max(5).required(), +}); + +module.exports = recoverPasswordSchema; diff --git a/src/validators/updateUser.js b/src/validators/updateUser.js new file mode 100644 index 0000000..795ac04 --- /dev/null +++ b/src/validators/updateUser.js @@ -0,0 +1,15 @@ +const Joi = require('joi'); + +const updateUserSchema = Joi.object({ + name: Joi.string() + .pattern(/^[A-Za-z][A-Za-z0-9 ]{2,30}$/) + .min(3) + .max(30), + + gender: Joi.string() + .pattern(/^male$|^female$|^non-binary$|^none$/) + .min(3) + .max(30), +}); + +module.exports = updateUserSchema; \ No newline at end of file diff --git a/yarn-error.log b/yarn-error.log index e69de29..13506ec 100644 --- a/yarn-error.log +++ b/yarn-error.log @@ -0,0 +1,5753 @@ +Arguments: + C:\Program Files\nodejs\node.exe C:\Users\LENOVO\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js install + +PATH: + C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Program Files\PuTTY\;C:\Program Files\OpenSSL-Win64\bin;C:\Program Files\MySQL\MySQL Server 8.0\bin;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;C:\Users\LENOVO\AppData\Local\Programs\Python\Python39\Scripts\;C:\Users\LENOVO\AppData\Local\Programs\Python\Python39\;C:\Users\LENOVO\AppData\Local\Microsoft\WindowsApps;C:\Users\LENOVO\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\heroku\bin;C:\Users\LENOVO\AppData\Roaming\npm;C:\Users\LENOVO\AppData\Local\Programs\mongosh\ + +Yarn version: + 1.22.19 + +Node version: + 16.14.2 + +Platform: + win32 x64 + +Trace: + Error: connect ECONNREFUSED 104.16.19.35:443 + at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16) + +npm manifest: + { + "name": "dinnerwithfriends.api", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "lint:fix": "eslint --fix .", + "test": "jest --watchAll --detectOpenHandles --runInBand", + "start": "node src/index.js", + "dev": "nodemon src/index.js", + "populate": "node src/utilities/populateDB.js", + "drop": "node src/utilities/dropDB.js" + }, + "keywords": [ + "example", + "heroku" + ], + "repository": { + "type": "git", + "url": "https://github.com/workshopapps/dinnerwithfriends.api.git" + }, + "author": "Ekene Nwobodo