Skip to content

Commit

Permalink
Merge branch 'debug-deployment-meeting-creation' into fix-migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
MinhxNguyen7 committed Jun 3, 2024
2 parents a1db1c3 + e757fca commit 6464c7d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
18 changes: 16 additions & 2 deletions src/lib/db/databaseUtils.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,16 @@ export const getExistingGuest = async (username: string, meeting: MeetingSelectS
* @returns The id of the inserted meeting.
*/
export const insertMeeting = async (meeting: MeetingInsertSchema, meetingDates: Date[]) => {
const [dbMeeting] = await db.insert(meetings).values(meeting).returning();
let dbMeeting: MeetingSelectSchema;

try {
[dbMeeting] = await db.insert(meetings).values(meeting).returning();
} catch (err) {
const meetingSerialized = JSON.stringify(meeting);
console.error("Error inserting meeting=", meetingSerialized);
throw Error(`Error inserting meeting=${meetingSerialized}`);
}

await insertMeetingDates(meetingDates, dbMeeting.id);
return dbMeeting.id;
};
Expand All @@ -132,7 +141,12 @@ export const insertMeetingDates = async (dates: Date[], meeting_id: string) => {
return { meeting_id, date: startOfDay };
});

await db.insert(meetingDates).values(dbMeetingDates);
try {
await db.insert(meetingDates).values(dbMeetingDates);
} catch (err) {
console.error("Error inserting meeting dates=", dbMeetingDates);
throw Error(`Error inserting meeting dates=${dbMeetingDates}`);
}
};

export const getExistingMeetingDates = async (meetingId: string) => {
Expand Down
11 changes: 6 additions & 5 deletions src/routes/api/create/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ export async function POST({ request }) {
console.log("Creating meeting:", title, description, fromTime, toTime, meetingDates);

if (fromTime >= toTime) {
error(400, "From time must be before to time");
throw error(400, "From time must be before to time");
}

if (meetingDates.length === 0) {
error(400, "At least one date must be provided");
throw error(400, "At least one date must be provided");
}

// Just so we don't get flooded too easily
if (meetingDates.length > 100) {
error(400, "Too many dates provided");
throw error(400, "Too many dates provided");
}

const sortedDates = meetingDates
Expand All @@ -41,7 +41,8 @@ export async function POST({ request }) {
const meetingId = await insertMeeting(meeting, sortedDates);
return json({ meetingId });
} catch (err) {
console.log("Error creating meeting:", err);
error(500, "Error creating meeting");
console.error("Error creating meeting:", err, meeting, sortedDates);
// TODO: This is unsafe
throw error(500, `Error creating meeting: ${err.message}`);
}
}
11 changes: 10 additions & 1 deletion sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default {
domainName: `${stack.stage === "prod" ? "" : `${stack.stage}.`}zotmeet.com`,
hostedZone: "zotmeet.com",
cdk: {
// @ts-expect-error Constructs types are broken, see https://github.com/sst/sst/issues/3483
certificate: Certificate.fromCertificateArn(
stack,
"MyCert",
Expand All @@ -30,5 +29,15 @@ export default {
});
stack.addOutputs({ url: site.url });
});

// Reference: https://docs.sst.dev/advanced/source-maps
app.setDefaultFunctionProps({
environment: {
NODE_OPTIONS: "--enable-source-maps",
},
nodejs: {
sourcemap: true,
},
});
},
} satisfies SSTConfig;

0 comments on commit 6464c7d

Please sign in to comment.