taleem-kernel 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/prisma/dev.db
CHANGED
|
Binary file
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Warnings:
|
|
3
|
+
|
|
4
|
+
- You are about to drop the column `groupings` on the `Course` table. All the data in the column will be lost.
|
|
5
|
+
|
|
6
|
+
*/
|
|
7
|
+
-- CreateTable
|
|
8
|
+
CREATE TABLE "Group" (
|
|
9
|
+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
10
|
+
"courseSlug" TEXT NOT NULL,
|
|
11
|
+
"slug" TEXT NOT NULL,
|
|
12
|
+
"title" TEXT NOT NULL,
|
|
13
|
+
"thumbnail" TEXT,
|
|
14
|
+
"items" JSONB NOT NULL
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
-- RedefineTables
|
|
18
|
+
PRAGMA defer_foreign_keys=ON;
|
|
19
|
+
PRAGMA foreign_keys=OFF;
|
|
20
|
+
CREATE TABLE "new_Course" (
|
|
21
|
+
"slug" TEXT NOT NULL,
|
|
22
|
+
"title" TEXT NOT NULL,
|
|
23
|
+
"description" TEXT,
|
|
24
|
+
"thumbnail" TEXT,
|
|
25
|
+
"access" TEXT NOT NULL DEFAULT 'OPEN',
|
|
26
|
+
"price" INTEGER NOT NULL DEFAULT 0
|
|
27
|
+
);
|
|
28
|
+
INSERT INTO "new_Course" ("access", "description", "price", "slug", "thumbnail", "title") SELECT "access", "description", "price", "slug", "thumbnail", "title" FROM "Course";
|
|
29
|
+
DROP TABLE "Course";
|
|
30
|
+
ALTER TABLE "new_Course" RENAME TO "Course";
|
|
31
|
+
CREATE UNIQUE INDEX "Course_slug_key" ON "Course"("slug");
|
|
32
|
+
PRAGMA foreign_keys=ON;
|
|
33
|
+
PRAGMA defer_foreign_keys=OFF;
|
|
34
|
+
|
|
35
|
+
-- CreateIndex
|
|
36
|
+
CREATE INDEX "Group_courseSlug_idx" ON "Group"("courseSlug");
|
|
37
|
+
|
|
38
|
+
-- CreateIndex
|
|
39
|
+
CREATE UNIQUE INDEX "Group_courseSlug_slug_key" ON "Group"("courseSlug", "slug");
|
package/prisma/schema.prisma
CHANGED
|
@@ -24,6 +24,18 @@ enum AdminRole {
|
|
|
24
24
|
SUPER_ADMIN
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
model Group {
|
|
28
|
+
id Int @id @default(autoincrement())
|
|
29
|
+
courseSlug String
|
|
30
|
+
slug String
|
|
31
|
+
title String
|
|
32
|
+
thumbnail String?
|
|
33
|
+
items Json
|
|
34
|
+
|
|
35
|
+
@@unique([courseSlug, slug])
|
|
36
|
+
@@index([courseSlug])
|
|
37
|
+
}
|
|
38
|
+
|
|
27
39
|
model Course {
|
|
28
40
|
slug String @unique
|
|
29
41
|
title String
|
|
@@ -31,7 +43,6 @@ model Course {
|
|
|
31
43
|
thumbnail String?
|
|
32
44
|
access CourseAccess @default(OPEN)
|
|
33
45
|
price Int @default(0)
|
|
34
|
-
groupings String @default("[]")
|
|
35
46
|
}
|
|
36
47
|
|
|
37
48
|
model User {
|
package/src/modules/Course.js
CHANGED
|
@@ -6,21 +6,49 @@ export default class Course {
|
|
|
6
6
|
if (filters.access) where.access = filters.access;
|
|
7
7
|
return this.kernel.db.course.findMany({ where });
|
|
8
8
|
}
|
|
9
|
-
|
|
10
9
|
async get(slug) {
|
|
11
10
|
return this.kernel.db.course.findUnique({ where: { slug } });
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
async getGroups(courseSlug) {
|
|
13
|
+
return this.kernel.db.group.findMany({
|
|
14
|
+
where: { courseSlug },
|
|
15
|
+
orderBy: { id: 'asc' }
|
|
16
|
+
});
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
async getGroup(courseSlug, groupSlug) {
|
|
19
|
+
return this.kernel.db.group.findUnique({
|
|
20
|
+
where: {
|
|
21
|
+
courseSlug_slug: { courseSlug, slug: groupSlug }
|
|
22
|
+
}
|
|
23
|
+
});
|
|
20
24
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return
|
|
25
|
+
async getGroupItems(courseSlug, groupSlug) {
|
|
26
|
+
const group = await this.getGroup(courseSlug, groupSlug);
|
|
27
|
+
return group?.items ?? [];
|
|
24
28
|
}
|
|
29
|
+
async wipe() {
|
|
30
|
+
await this.kernel.db.group.deleteMany();
|
|
31
|
+
await this.kernel.db.course.deleteMany();
|
|
32
|
+
}
|
|
33
|
+
async seed(course) {
|
|
34
|
+
const { groupings = [], ...courseData } = course;
|
|
35
|
+
|
|
36
|
+
const created = await this.kernel.db.course.create({
|
|
37
|
+
data: courseData
|
|
38
|
+
});
|
|
25
39
|
|
|
40
|
+
for (const group of groupings) {
|
|
41
|
+
await this.kernel.db.group.create({
|
|
42
|
+
data: {
|
|
43
|
+
courseSlug: created.slug,
|
|
44
|
+
slug: group.slug,
|
|
45
|
+
title: group.title,
|
|
46
|
+
thumbnail: group.thumbnail ?? null,
|
|
47
|
+
items: group.items ?? []
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return created;
|
|
53
|
+
}
|
|
26
54
|
}
|
package/src/modules/Library.js
CHANGED