Skip to content

Commit 7b966f8

Browse files
author
Rajat
committed
WIP: cleanup school resource script
1 parent fa0885c commit 7b966f8

30 files changed

Lines changed: 1065 additions & 68 deletions

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/dev/types/routes.d.ts";
3+
import "./.next/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/.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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
"mongoose": "^8.13.1"
49+
}
50+
}

packages/orm-models/src/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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";
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import mongoose from "mongoose";
2+
import { generateUniqueId } from "@courselit/utils";
3+
import {
4+
Constants,
5+
Course,
6+
type ProductAccessType,
7+
type Group,
8+
} from "@courselit/common-models";
9+
import { MediaSchema } from "./media";
10+
import { EmailSchema } from "./email";
11+
12+
export interface InternalCourse extends Omit<Course, "paymentPlans"> {
13+
domain: mongoose.Types.ObjectId;
14+
id: mongoose.Types.ObjectId;
15+
privacy: ProductAccessType;
16+
published: boolean;
17+
isFeatured: boolean;
18+
tags: string[];
19+
lessons: any[];
20+
sales: number;
21+
customers: string[];
22+
certificate?: boolean;
23+
}
24+
25+
export const CourseSchema = new mongoose.Schema<InternalCourse>(
26+
{
27+
domain: { type: mongoose.Schema.Types.ObjectId, required: true },
28+
courseId: { type: String, required: true, default: generateUniqueId },
29+
title: { type: String, required: true },
30+
slug: { type: String, required: true },
31+
cost: { type: Number, required: true },
32+
costType: {
33+
type: String,
34+
required: true,
35+
enum: ["free", "email", "paid"],
36+
},
37+
privacy: {
38+
type: String,
39+
required: true,
40+
enum: Object.values(Constants.ProductAccessType),
41+
},
42+
type: {
43+
type: String,
44+
required: true,
45+
enum: Object.values(Constants.CourseType),
46+
},
47+
creatorId: { type: String, required: true },
48+
published: { type: Boolean, required: true, default: false },
49+
tags: [{ type: String }],
50+
lessons: [String],
51+
description: String,
52+
featuredImage: MediaSchema,
53+
groups: [
54+
{
55+
name: { type: String, required: true },
56+
_id: {
57+
type: String,
58+
required: true,
59+
default: generateUniqueId,
60+
},
61+
rank: { type: Number, required: true },
62+
collapsed: { type: Boolean, required: true, default: true },
63+
lessonsOrder: { type: [String] },
64+
drip: new mongoose.Schema<Group["drip"]>({
65+
type: {
66+
type: String,
67+
required: true,
68+
enum: Constants.dripType,
69+
},
70+
status: { type: Boolean, required: true, default: false },
71+
delayInMillis: { type: Number },
72+
dateInUTC: { type: Number },
73+
email: EmailSchema,
74+
}),
75+
},
76+
],
77+
sales: { type: Number, required: true, default: 0.0 },
78+
customers: [String],
79+
pageId: { type: String },
80+
// paymentPlans: [String],
81+
defaultPaymentPlan: { type: String },
82+
leadMagnet: { type: Boolean, required: true, default: false },
83+
certificate: Boolean,
84+
},
85+
{
86+
timestamps: true,
87+
},
88+
);
89+
90+
CourseSchema.index({
91+
title: "text",
92+
});
93+
94+
CourseSchema.index({ domain: 1, title: 1 }, { unique: true });
95+
96+
CourseSchema.statics.paginatedFind = async function (
97+
filter,
98+
options: {
99+
page?: number;
100+
limit?: number;
101+
sort?: number;
102+
},
103+
) {
104+
const page = options.page || 1;
105+
const limit = options.limit || 10;
106+
const sort = options.sort || -1;
107+
const skip = (page - 1) * limit;
108+
109+
const docs = await this.find(filter)
110+
.sort({ createdAt: sort })
111+
.lean()
112+
.skip(skip)
113+
.limit(limit)
114+
.exec();
115+
return docs;
116+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import mongoose from "mongoose";
2+
import { SettingsSchema } from "./site-info";
3+
import { Domain as PublicDomain } from "@courselit/common-models";
4+
5+
export interface Domain extends PublicDomain {
6+
_id: mongoose.Types.ObjectId;
7+
lastEditedThemeId?: string;
8+
}
9+
10+
export const DomainSchema = new mongoose.Schema<Domain>(
11+
{
12+
name: { type: String, required: true, unique: true },
13+
customDomain: { type: String, unique: true, sparse: true },
14+
email: { type: String, required: true },
15+
deleted: { type: Boolean, required: true, default: false },
16+
settings: SettingsSchema,
17+
themeId: { type: String },
18+
lastEditedThemeId: { type: String },
19+
sharedWidgets: {
20+
type: mongoose.Schema.Types.Mixed,
21+
default: {},
22+
},
23+
draftSharedWidgets: {
24+
type: mongoose.Schema.Types.Mixed,
25+
default: {},
26+
},
27+
firstRun: { type: Boolean, required: true, default: false },
28+
tags: { type: [String], default: [] },
29+
checkSubscriptionStatusAfter: { type: Date },
30+
quota: new mongoose.Schema<Domain["quota"]>({
31+
mail: new mongoose.Schema<Domain["quota"]["mail"]>({
32+
daily: { type: Number, default: 0 },
33+
monthly: { type: Number, default: 0 },
34+
dailyCount: { type: Number, default: 0 },
35+
monthlyCount: { type: Number, default: 0 },
36+
lastDailyCountUpdate: { type: Date, default: Date.now },
37+
lastMonthlyCountUpdate: { type: Date, default: Date.now },
38+
}),
39+
}),
40+
},
41+
{
42+
timestamps: true,
43+
},
44+
);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import mongoose from "mongoose";
2+
3+
export const EmailDeliverySchema = new mongoose.Schema(
4+
{
5+
domain: { type: mongoose.Schema.Types.ObjectId, required: true },
6+
sequenceId: { type: String, required: true },
7+
userId: { type: String, required: true },
8+
emailId: { type: String, required: true },
9+
},
10+
{
11+
timestamps: { createdAt: true, updatedAt: false },
12+
},
13+
);

0 commit comments

Comments
 (0)