Skip to content

Commit ac5d882

Browse files
committed
feat: Remove emailNotifications table
1 parent 5607406 commit ac5d882

File tree

2 files changed

+17
-54
lines changed

2 files changed

+17
-54
lines changed

apps/web/app/api/desktop/video/create/route.ts

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { NextRequest } from "next/server";
22
import { db } from "@cap/database";
3-
import { s3Buckets, videos, users, emailNotifications } from "@cap/database/schema";
3+
import { s3Buckets, videos, users } from "@cap/database/schema";
44
import { getCurrentUser } from "@cap/database/auth/session";
55
import { nanoId } from "@cap/database/helpers";
66
import { cookies } from "next/headers";
@@ -206,49 +206,26 @@ export async function GET(req: NextRequest) {
206206
.where(eq(videos.ownerId, user.id));
207207

208208
if (videoCount && videoCount[0] && videoCount[0].count === 1 && user.email) {
209-
// Check if we've already sent this email
210-
const existingNotifications = await db
211-
.select({ id: emailNotifications.id })
212-
.from(emailNotifications)
213-
.where(
214-
and(
215-
eq(emailNotifications.userId, user.id),
216-
eq(emailNotifications.type, "first_shareable_link")
217-
)
218-
)
219-
.limit(1);
209+
console.log("[SendFirstShareableLinkEmail] Sending first shareable link email with 5-minute delay");
220210

221-
// If we've already sent this email, don't send it again
222-
if (!existingNotifications || existingNotifications.length === 0) {
223-
console.log("[SendFirstShareableLinkEmail] Sending first shareable link email with 5-minute delay");
211+
const videoUrl = clientEnv.NEXT_PUBLIC_IS_CAP
212+
? `https://cap.link/${id}`
213+
: `${clientEnv.NEXT_PUBLIC_WEB_URL}/s/${id}`;
224214

225-
const videoUrl = clientEnv.NEXT_PUBLIC_IS_CAP
226-
? `https://cap.link/${id}`
227-
: `${clientEnv.NEXT_PUBLIC_WEB_URL}/s/${id}`;
228-
229-
// Record that we're sending this email
230-
const shortId = nanoId().substring(0, 15);
231-
await db.insert(emailNotifications).values({
232-
id: shortId,
233-
userId: user.id,
234-
type: "first_shareable_link",
235-
});
236-
237-
// Send email with 5-minute delay using Resend's scheduling feature
238-
await sendEmail({
215+
// Send email with 5-minute delay using Resend's scheduling feature
216+
await sendEmail({
217+
email: user.email,
218+
subject: "You created your first Cap! 🥳",
219+
react: FirstShareableLink({
239220
email: user.email,
240-
subject: "You created your first Cap! 🥳",
241-
react: FirstShareableLink({
242-
email: user.email,
243-
url: videoUrl,
244-
videoName: videoData.name,
245-
}),
246-
marketing: true,
247-
scheduledAt: "in 5 min"
248-
});
221+
url: videoUrl,
222+
videoName: videoData.name,
223+
}),
224+
marketing: true,
225+
scheduledAt: "in 5 min"
226+
});
249227

250-
console.log("[SendFirstShareableLinkEmail] First shareable link email scheduled to be sent in 5 minutes");
251-
}
228+
console.log("[SendFirstShareableLinkEmail] First shareable link email scheduled to be sent in 5 minutes");
252229
}
253230
} catch (error) {
254231
console.error("Error checking for first video or sending email:", error);

packages/database/schema.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -268,20 +268,6 @@ export const comments = mysqlTable(
268268
})
269269
);
270270

271-
// Add a new table to track email notifications
272-
export const emailNotifications = mysqlTable(
273-
"email_notifications",
274-
{
275-
id: nanoId("id").notNull().primaryKey().unique(),
276-
userId: nanoId("userId").notNull(),
277-
type: varchar("type", { length: 255 }).notNull(),
278-
sentAt: timestamp("sentAt").notNull().defaultNow(),
279-
},
280-
(table) => ({
281-
userIdTypeIndex: index("user_id_type_idx").on(table.userId, table.type),
282-
})
283-
);
284-
285271
export const s3Buckets = mysqlTable("s3_buckets", {
286272
id: nanoId("id").notNull().primaryKey().unique(),
287273
ownerId: nanoId("ownerId").notNull(),

0 commit comments

Comments
 (0)