Skip to content

Commit 18f1972

Browse files
author
Rajat
committed
clean up script
1 parent 7161460 commit 18f1972

31 files changed

Lines changed: 1363 additions & 13 deletions

apps/web/models/Widget.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,3 @@ export const WidgetSchema = new mongoose.Schema<WidgetInstance>({
99
shared: { type: Boolean, required: true, default: false },
1010
settings: mongoose.Schema.Types.Mixed,
1111
});
12-
13-
const WidgetModel =
14-
mongoose.models.Widget || mongoose.model("Widget", WidgetSchema);
15-
16-
export default WidgetModel;

apps/web/next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
import "./.next/types/routes.d.ts";
3+
import "./.next/dev/types/routes.d.ts";
44

55
// NOTE: This file should not be edited
66
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

packages/orm-models/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@courselit/common-models": "workspace:^",
4646
"@courselit/utils": "workspace:^",
4747
"@courselit/email-editor": "workspace:^",
48+
"@courselit/page-models": "workspace:^",
4849
"mongoose": "^8.13.1"
4950
}
50-
}
51+
}

packages/orm-models/src/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,23 @@ export * from "./models/email-event";
1212
export * from "./models/subscriber";
1313
export * from "./models/domain";
1414
export * from "./models/site-info";
15+
export * from "./models/lesson";
16+
export * from "./models/certificate";
17+
export * from "./models/certificate-template";
18+
export * from "./models/payment-plan";
19+
export * from "./models/activity";
20+
export * from "./models/lesson-evaluation";
21+
export * from "./models/page";
22+
export * from "./models/community";
23+
export * from "./models/community-report";
24+
export * from "./models/community-post-subscriber";
25+
export * from "./models/community-comment";
26+
export * from "./models/community-media";
27+
export * from "./models/community-post";
28+
export * from "./models/invoice";
29+
export * from "./models/theme";
30+
export * from "./models/ongoing-sequence";
31+
export * from "./models/notification";
32+
export * from "./models/download-link";
33+
export * from "./models/apikey";
34+
export * from "./models/user-theme";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import mongoose from "mongoose";
2+
import { ActivityType, Constants } from "@courselit/common-models";
3+
4+
export interface Activity {
5+
domain: mongoose.Types.ObjectId;
6+
userId: string;
7+
type: ActivityType;
8+
entityId?: string;
9+
metadata?: Record<string, any>;
10+
createdAt?: Date;
11+
updatedAt?: Date;
12+
}
13+
14+
export const ActivitySchema = new mongoose.Schema<Activity>(
15+
{
16+
domain: { type: mongoose.Schema.Types.ObjectId, required: true },
17+
userId: { type: String, required: true },
18+
type: {
19+
type: String,
20+
required: true,
21+
enum: Object.values(Constants.ActivityType),
22+
},
23+
entityId: { type: String },
24+
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
25+
},
26+
{
27+
timestamps: true,
28+
},
29+
);
30+
31+
ActivitySchema.index({ domain: 1, type: 1, createdAt: 1 });
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { generateUniqueId } from "@courselit/utils";
2+
import mongoose from "mongoose";
3+
4+
export interface ApiKey {
5+
domain: mongoose.Types.ObjectId;
6+
keyId: string;
7+
name: string;
8+
key: string;
9+
}
10+
11+
export const ApiKeySchema = new mongoose.Schema<ApiKey>(
12+
{
13+
domain: { type: mongoose.Schema.Types.ObjectId, required: true },
14+
keyId: { type: String, required: true, default: generateUniqueId },
15+
name: { type: String, required: true },
16+
key: { type: String, required: true, default: generateUniqueId },
17+
},
18+
{
19+
timestamps: true,
20+
},
21+
);
22+
23+
ApiKeySchema.index(
24+
{
25+
domain: 1,
26+
name: 1,
27+
},
28+
{ unique: true },
29+
);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Media } from "@courselit/common-models";
2+
import { generateUniqueId } from "@courselit/utils";
3+
import mongoose from "mongoose";
4+
import { MediaSchema } from "./media";
5+
6+
export interface InternalCertificateTemplate {
7+
domain: mongoose.Types.ObjectId;
8+
templateId: string;
9+
courseId: string;
10+
title: string;
11+
subtitle: string;
12+
description: string;
13+
signatureImage: Media;
14+
signatureName: string;
15+
signatureDesignation?: string;
16+
logo?: Media;
17+
createdAt: Date;
18+
updatedAt: Date;
19+
}
20+
21+
export const CertificateTemplateSchema =
22+
new mongoose.Schema<InternalCertificateTemplate>(
23+
{
24+
domain: { type: mongoose.Schema.Types.ObjectId, required: true },
25+
templateId: {
26+
type: String,
27+
required: true,
28+
unique: true,
29+
default: generateUniqueId,
30+
},
31+
courseId: { type: String, required: true },
32+
title: { type: String, required: true },
33+
subtitle: { type: String, required: true },
34+
description: { type: String, required: true },
35+
signatureImage: MediaSchema,
36+
signatureName: { type: String, required: true },
37+
signatureDesignation: { type: String },
38+
logo: MediaSchema,
39+
},
40+
{
41+
timestamps: true,
42+
},
43+
);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { generateUniqueId } from "@courselit/utils";
2+
import mongoose from "mongoose";
3+
4+
export interface InternalCertificate {
5+
domain: mongoose.Types.ObjectId;
6+
certificateId: string;
7+
userId: string;
8+
courseId: string;
9+
createdAt: Date;
10+
updatedAt: Date;
11+
}
12+
13+
export const CertificateSchema = new mongoose.Schema<InternalCertificate>(
14+
{
15+
domain: { type: mongoose.Schema.Types.ObjectId, required: true },
16+
certificateId: {
17+
type: String,
18+
required: true,
19+
unique: true,
20+
default: generateUniqueId,
21+
},
22+
userId: { type: String, required: true },
23+
courseId: { type: String, required: true },
24+
},
25+
{
26+
timestamps: true,
27+
},
28+
);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { generateUniqueId } from "@courselit/utils";
2+
import mongoose from "mongoose";
3+
import { CommunityMediaSchema } from "./community-media";
4+
import {
5+
CommunityComment,
6+
CommunityCommentReply,
7+
} from "@courselit/common-models";
8+
9+
export interface InternalCommunityComment
10+
extends Pick<
11+
CommunityComment,
12+
"communityId" | "postId" | "commentId" | "content" | "media"
13+
> {
14+
domain: mongoose.Types.ObjectId;
15+
userId: string;
16+
likes: string[];
17+
replies: InternalReply[];
18+
deleted: boolean;
19+
}
20+
21+
export interface InternalReply
22+
extends Omit<CommunityCommentReply, "likesCount" | "hasLiked"> {
23+
userId: string;
24+
likes: string[];
25+
}
26+
27+
export const ReplySchema = new mongoose.Schema(
28+
{
29+
userId: { type: String, required: true },
30+
content: { type: String, required: true },
31+
media: [CommunityMediaSchema],
32+
replyId: { type: String, required: true, default: generateUniqueId },
33+
parentReplyId: { type: String, default: null },
34+
likes: [String],
35+
deleted: { type: Boolean, default: false },
36+
},
37+
{
38+
timestamps: true,
39+
},
40+
);
41+
42+
export const CommunityCommentSchema =
43+
new mongoose.Schema<InternalCommunityComment>(
44+
{
45+
domain: { type: mongoose.Schema.Types.ObjectId, required: true },
46+
userId: { type: String, required: true },
47+
communityId: { type: String, required: true },
48+
postId: { type: String, required: true },
49+
commentId: {
50+
type: String,
51+
required: true,
52+
unique: true,
53+
default: generateUniqueId,
54+
},
55+
content: { type: String, required: true },
56+
media: [CommunityMediaSchema],
57+
likes: [String],
58+
replies: [ReplySchema],
59+
deleted: { type: Boolean, required: true, default: false },
60+
},
61+
{
62+
timestamps: true,
63+
},
64+
);
65+
66+
CommunityCommentSchema.statics.paginatedFind = async function (
67+
filter,
68+
options,
69+
) {
70+
const page = options.page || 1;
71+
const limit = options.limit || 10;
72+
const skip = (page - 1) * limit;
73+
74+
const docs = await this.find(filter).skip(skip).limit(limit).exec();
75+
return docs;
76+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import mongoose from "mongoose";
2+
import { MediaSchema } from "./media";
3+
import { CommunityMedia } from "@courselit/common-models";
4+
5+
export const CommunityMediaSchema = new mongoose.Schema<CommunityMedia>({
6+
type: { type: String, required: true },
7+
title: { type: String, required: true },
8+
url: { type: String },
9+
media: MediaSchema,
10+
});

0 commit comments

Comments
 (0)