Skip to content

Commit d41af16

Browse files
author
Rajat Saxena
committed
DB migrations; UI enhancements;
1 parent d0edb9b commit d41af16

File tree

55 files changed

+1702
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1702
-206
lines changed

.yarn/cache/@next-env-npm-14.2.4-9859535528-ff47297f95.zip renamed to .yarn/cache/@next-env-npm-14.2.25-22db491964-c937d4e8b6.zip

5.66 KB
Binary file not shown.

.yarn/cache/@next-swc-darwin-arm64-npm-14.2.4-86d534c3ee-8.zip renamed to .yarn/cache/@next-swc-darwin-arm64-npm-14.2.25-3d28e40873-8.zip

33.9 MB
Binary file not shown.
-38.8 MB
Binary file not shown.

.yarn/cache/next-npm-14.2.4-37fb4e5b51-3b858cfec2.zip renamed to .yarn/cache/next-npm-14.2.25-cd023f1b24-ca47d0f1d4.zip

23.1 MB
Binary file not shown.
-705 KB
Binary file not shown.

apps/queue/src/domain/process-drip.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { InternalUser } from "@courselit/common-logic";
21
import CourseModel, { Course } from "./model/course";
32
import UserModel from "./model/user";
43
import mailQueue from "./queue";
54
import { Liquid } from "liquidjs";
5+
import { getMemberships } from "./queries";
6+
import { Constants } from "@courselit/common-models";
7+
import { InternalUser } from "@courselit/common-logic";
68
const liquidEngine = new Liquid();
79

810
export async function processDrip() {
@@ -32,9 +34,17 @@ export async function processDrip() {
3234
)
3335
.map((group) => group.id);
3436

37+
const memberships = await getMemberships(
38+
course.courseId,
39+
Constants.MembershipEntityType.COURSE,
40+
);
3541
const users: InternalUser[] = await UserModel.find({
36-
"purchases.courseId": course.courseId,
42+
domain: course.domain,
43+
userId: { $in: memberships.map((m) => m.userId) },
3744
});
45+
// const users: InternalUser[] = await UserModel.find({
46+
// "purchases.courseId": course.courseId,
47+
// });
3848

3949
for (const user of users) {
4050
const userProgressInCourse = user.purchases.find(

apps/queue/src/domain/queries.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ import OngoingSequenceModel, {
33
OngoingSequence,
44
} from "./model/ongoing-sequence";
55
import SequenceModel from "./model/sequence";
6+
import MembershipModel from "./model/membership";
67
import UserModel from "./model/user";
78
import RuleModel from "./model/rule";
89
import mongoose from "mongoose";
910
import DomainModel from "./model/domain";
1011
import { Constants, EmailTemplate } from "@courselit/common-models";
1112
import emailTemplate from "./model/email-template";
12-
import { AdminSequence, InternalUser } from "@courselit/common-logic";
13+
import {
14+
AdminSequence,
15+
InternalMembership,
16+
InternalUser,
17+
} from "@courselit/common-logic";
1318

1419
export async function getDueOngoingSequences(): Promise<OngoingSequence[]> {
1520
const currentTime = new Date().getTime();
@@ -61,3 +66,11 @@ export async function getDomain(id: mongoose.Schema.Types.ObjectId) {
6166
export async function getTemplate(id: string): Promise<EmailTemplate | null> {
6267
return (await emailTemplate.find({ templateId: id }).lean()) as any;
6368
}
69+
70+
export async function getMemberships(entityId: string, entityType: string) {
71+
return await MembershipModel.find<InternalMembership>({
72+
entityId,
73+
entityType,
74+
status: Constants.MembershipStatus.ACTIVE,
75+
});
76+
}

apps/web/.migrations/create-free-payment-plan.js renamed to apps/web/.migrations/19-03-25_00-00-create-internal-payment-plan.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ const setupFreePayment = async () => {
8484
domain: domain._id,
8585
permissions: { $elemMatch: { $eq: "site:manage" } },
8686
});
87+
if (!creator) {
88+
console.log("No creator found for domain", domain.name);
89+
const users = await User.find({
90+
domain: domain._id,
91+
});
92+
console.log(`Other users for ${domain.name}:`, users);
93+
continue;
94+
}
95+
const existingPaymentPlan = await PaymentPlan.findOne({
96+
domain: domain._id,
97+
internal: true,
98+
});
99+
if (existingPaymentPlan) {
100+
console.log("Payment plan already exists for domain", domain.name);
101+
continue;
102+
}
87103
const paymentPlan = await PaymentPlan.create({
88104
domain: domain._id,
89105
name: "Internal Payment Plan",
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import mongoose from "mongoose";
2+
3+
mongoose.connect(process.env.DB_CONNECTION_STRING, {
4+
useNewUrlParser: true,
5+
useUnifiedTopology: true,
6+
});
7+
8+
const DomainSchema = new mongoose.Schema({
9+
name: { type: String, required: true, unique: true },
10+
sharedWidgets: {
11+
type: mongoose.Schema.Types.Mixed,
12+
default: {},
13+
},
14+
});
15+
16+
const Domain = mongoose.model("Domain", DomainSchema);
17+
18+
const updateLinks = async () => {
19+
const domains = await Domain.find({});
20+
let updatedCount = 0;
21+
22+
for (const domain of domains) {
23+
let needsUpdate = false;
24+
const sharedWidgets = domain.sharedWidgets || {};
25+
26+
// Update header widget links
27+
if (sharedWidgets.header?.settings?.links) {
28+
sharedWidgets.header.settings.links =
29+
sharedWidgets.header.settings.links.map((link) => {
30+
if (link.href === "/courses") {
31+
needsUpdate = true;
32+
return {
33+
...link,
34+
href: "/products",
35+
label: "Products",
36+
};
37+
}
38+
return link;
39+
});
40+
}
41+
42+
// Update any other widgets that might have /courses links
43+
for (const widgetKey in sharedWidgets) {
44+
const widget = sharedWidgets[widgetKey];
45+
if (widget?.settings?.links) {
46+
widget.settings.links = widget.settings.links.map((link) => {
47+
if (link.href === "/courses") {
48+
needsUpdate = true;
49+
return {
50+
...link,
51+
href: "/products",
52+
label: "Products",
53+
};
54+
}
55+
return link;
56+
});
57+
}
58+
}
59+
60+
if (needsUpdate) {
61+
domain.markModified("sharedWidgets");
62+
await domain.save();
63+
updatedCount++;
64+
console.log(`Updated links for domain: ${domain.name}`);
65+
}
66+
}
67+
68+
console.log(`Migration completed. Updated ${updatedCount} domains.`);
69+
};
70+
71+
(async () => {
72+
try {
73+
await updateLinks();
74+
console.log("Migration completed successfully");
75+
} catch (error) {
76+
console.error("Migration failed:", error);
77+
} finally {
78+
mongoose.connection.close();
79+
}
80+
})();

0 commit comments

Comments
 (0)