Skip to content

Commit 9e2e9ec

Browse files
rajat1saxenaRajat
andauthored
Utility scripts (#693)
* WIP: cleanup school resource script * Lint fixes * clean up script * Lint fixes --------- Co-authored-by: Rajat <hi@rajatsaxena.dev>
1 parent 5b9830f commit 9e2e9ec

Some content is hidden

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

53 files changed

+2834
-109
lines changed

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;

packages/orm-models/.eslintrc.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
parser: "@typescript-eslint/parser",
3+
plugins: ["@typescript-eslint"],
4+
extends: [
5+
"eslint:recommended",
6+
"plugin:@typescript-eslint/eslint-recommended",
7+
"plugin:@typescript-eslint/recommended",
8+
],
9+
env: {
10+
node: true,
11+
},
12+
rules: {
13+
"no-console": ["error", { allow: ["warn"] }],
14+
},
15+
ignorePatterns: ["dist/**/*.*"],
16+
};

packages/orm-models/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
3+
dist/

packages/orm-models/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `@courselit/common-orm-models`
2+
3+
ORM models for CourseLit
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module "mongoose";

packages/orm-models/package.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "@courselit/orm-models",
3+
"version": "0.0.1",
4+
"description": "Common ORM models for CourseLit",
5+
"author": "Team CourseLit <hi@codelit.dev>",
6+
"homepage": "https://github.com/codelitdev/courselit#readme",
7+
"private": true,
8+
"license": "MIT",
9+
"types": "dist/index.d.ts",
10+
"exports": {
11+
".": {
12+
"import": "./dist/index.mjs",
13+
"require": "./dist/index.cjs"
14+
}
15+
},
16+
"publishConfig": {
17+
"access": "public"
18+
},
19+
"repository": {
20+
"type": "git",
21+
"url": "git+https://github.com/codelitdev/courselit.git"
22+
},
23+
"scripts": {
24+
"test": "echo \"Error: run tests from root\" && exit 1",
25+
"clean": "rimraf dist/",
26+
"prepublishOnly": "pnpm run build",
27+
"build": "tsup",
28+
"tsc:build": "tsc",
29+
"dev": "tsup --watch",
30+
"check-types": "tsc --noEmit"
31+
},
32+
"bugs": {
33+
"url": "https://github.com/codelitdev/courselit/issues"
34+
},
35+
"devDependencies": {
36+
"@typescript-eslint/eslint-plugin": "^8.46.0",
37+
"@typescript-eslint/parser": "^8.46.0",
38+
"tsconfig": "workspace:^",
39+
"eslint": "^8.12.0",
40+
"rimraf": "^4.1.1",
41+
"tsup": "6.6.0",
42+
"typescript": "^4.9.5"
43+
},
44+
"dependencies": {
45+
"@courselit/common-models": "workspace:^",
46+
"@courselit/utils": "workspace:^",
47+
"@courselit/email-editor": "workspace:^",
48+
"@courselit/page-models": "workspace:^",
49+
"mongoose": "^8.13.1"
50+
}
51+
}

packages/orm-models/src/index.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export * from "./models/user";
2+
export * from "./models/membership";
3+
export * from "./models/media";
4+
export * from "./models/sequence";
5+
export * from "./models/user-segment";
6+
export * from "./models/user-filter";
7+
export * from "./models/course";
8+
export * from "./models/rule";
9+
export * from "./models/email";
10+
export * from "./models/email-delivery";
11+
export * from "./models/email-event";
12+
export * from "./models/subscriber";
13+
export * from "./models/domain";
14+
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+
);

0 commit comments

Comments
 (0)