Skip to content

Commit

Permalink
Add new thread on create event
Browse files Browse the repository at this point in the history
  • Loading branch information
robertgodfrey committed Nov 10, 2023
1 parent 477853c commit 765593c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions my-app/src/models/threads/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const threadSchema = new Schema({
messages: {
type: [Message],
required: true,
default: [],
},
});

Expand Down
10 changes: 8 additions & 2 deletions my-app/src/pages/api/mongo/event/add-dev.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import connectDB from '@/lib/mongodb';
import Event from '@/models/event';
import { findCloseIsland } from "@/utils/findCloseIsland";
import Organization from "@/models/organization";
import Thread from "@/models/threads/thread";
import { findCloseIsland } from "@/utils/findCloseIsland";

/*
Expand Down Expand Up @@ -41,7 +42,7 @@ export default async function handler(req, res) {

const matchingOrgs = await Organization.find({ location: derivedClosetIsland });

await Event.create({
const newEvent = await Event.create({
status,
publicType,
publicTypeDesc,
Expand All @@ -68,6 +69,11 @@ export default async function handler(req, res) {
phoneNumber,
},
});

await Thread.create({
eventId: newEvent._id,
});

res.status(201).json({msg: 'Event reported'});
} catch (error) {
console.log(error);
Expand Down
5 changes: 5 additions & 0 deletions my-app/src/pages/api/mongo/event/add-dialogflow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import connectDB from '@/lib/mongodb';
import Event from '@/models/event';
import { sendEmail } from '@/server/mailService';
import Thread from "@/models/threads/thread";

export default async function handler(req, res) {
if (req.method === 'POST') {
Expand Down Expand Up @@ -66,6 +67,10 @@ export default async function handler(req, res) {

const created = await Event.create(eventDetails);

await Thread.create({
eventId: created._id,
});

const containerFullness = publicContainerFullness ? `<b>Container Fullness:</b> ${publicContainerFullness}<br/>` : '';
const claimBoat = publicClaimBoat ? `<b>Intend to Claim Boat:</b> ${publicClaimBoat}<br/>` : '';
const latLongOrPositionDescription = publicLatLongOrPositionDesc ? `<b>Position Description:</b> ${publicLatLongOrPositionDesc}<br/>` : '';
Expand Down
5 changes: 5 additions & 0 deletions my-app/src/pages/api/mongo/event/add-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import connectDB from '@/lib/mongodb';
import Event from '@/models/event';
import { sendEmail } from '@/server/mailService';
import { findCloseIsland } from "@/utils/findCloseIsland";
import Thread from "@/models/threads/thread";

export default async function handler(req, res) {
if (req.method === 'POST') {
Expand Down Expand Up @@ -57,6 +58,10 @@ export default async function handler(req, res) {
},
});

await Thread.create({
eventId: created._id,
});

const containerFullness = publicContainerFullness ? `<b>Container Fullness:</b> ${publicContainerFullness}<br/>` : '';
const claimBoat = publicClaimBoat ? `<b>Intend to Claim Boat:</b> ${publicClaimBoat}<br/>` : '';
const latLongOrPositionDescription = publicLatLongOrPositionDesc ? `<b>Position Description:</b> ${publicLatLongOrPositionDesc}<br/>` : '';
Expand Down

0 comments on commit 765593c

Please sign in to comment.