Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
Latest changes, ticket should be ready for review
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinLemon112 committed Mar 3, 2024
1 parent 6170820 commit 38eb1c7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/notification/publish/publish.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import express from 'express';
import mqtt, { MqttClient } from 'mqtt';
import { v1 as uuidv1 } from 'uuid';
import mongoose, { Schema, Document } from 'mongoose';
import mongoose, { Schema, Document, ConnectOptions } from 'mongoose';
import dotenv from 'dotenv';
dotenv.config();
import db from './db'; // Import the db.ts file to access the dbURI variable


const server = express();
const options = {
username: process.env.ACTIVE_MQ_USERNAME,
Expand All @@ -14,7 +15,7 @@ const options = {
port: 1883,
};
const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion

server.use(express.json());
// MongoDB event schema and model
interface accounts extends Document {
email: string;
Expand All @@ -27,7 +28,10 @@ const accountSchema = new Schema<accounts>({
});

// Establish Mongoose connection
mongoose.connect(db.dbURI)
mongoose.connect(db.dbURI, {
useNewUrlParser: true,
useUnifiedTopology: true,
} as ConnectOptions)
.then(() => {
console.log('MongoDB connected');

Expand Down Expand Up @@ -77,7 +81,6 @@ mongoose.connect(db.dbURI)
const newEvent = await eventData.save(); // Save the new document to the database
res.json(newEvent);

res.status(201).json(newEvent); // HTTP 201 Created status code for successful creation
} catch (error) {
console.error(error);
res.status(500).json({ error: 'Internal Server Error' });
Expand Down

0 comments on commit 38eb1c7

Please sign in to comment.