feat: implement micro-learning collections and completion tracking hook
This commit is contained in:
@@ -1,12 +1,30 @@
|
|||||||
/// <reference path="../pb_data/types.d.ts" />
|
/// <reference path="../pb_data/types.d.ts" />
|
||||||
migrate((app) => {
|
migrate((app) => {
|
||||||
|
const topicsCollectionId = "pbc_2800040823";
|
||||||
|
const teamMembersCollectionId = "pbc_3980519374";
|
||||||
|
|
||||||
// Create micro_learnings collection
|
// Create micro_learnings collection
|
||||||
const microLearnings = new Collection({
|
const microLearnings = new Collection({
|
||||||
"id": "pbc_micro_learnings_0",
|
"id": "pbc_micro_learnings_0",
|
||||||
"name": "micro_learnings",
|
"name": "micro_learnings",
|
||||||
"type": "base",
|
"type": "base",
|
||||||
"system": false,
|
"system": false,
|
||||||
"schema": [
|
"fields": [
|
||||||
|
{
|
||||||
|
"autogeneratePattern": "[a-z0-9]{15}",
|
||||||
|
"help": "",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "text_id_ml",
|
||||||
|
"max": 15,
|
||||||
|
"min": 15,
|
||||||
|
"name": "id",
|
||||||
|
"pattern": "^[a-z0-9]+$",
|
||||||
|
"presentable": false,
|
||||||
|
"primaryKey": true,
|
||||||
|
"required": true,
|
||||||
|
"system": true,
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"system": false,
|
"system": false,
|
||||||
"id": "rel_topic_id",
|
"id": "rel_topic_id",
|
||||||
@@ -14,13 +32,11 @@ migrate((app) => {
|
|||||||
"type": "relation",
|
"type": "relation",
|
||||||
"required": true,
|
"required": true,
|
||||||
"presentable": false,
|
"presentable": false,
|
||||||
"options": {
|
"collectionId": topicsCollectionId,
|
||||||
"collectionId": "pbc_2800040823", // the ID for topics from snapshot (we will use topic name later if possible, but let's just use collectionName: "topics")
|
|
||||||
"cascadeDelete": true,
|
"cascadeDelete": true,
|
||||||
"minSelect": null,
|
"minSelect": null,
|
||||||
"maxSelect": 1,
|
"maxSelect": 1,
|
||||||
"displayFields": null
|
"displayFields": null
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"system": false,
|
"system": false,
|
||||||
@@ -29,7 +45,6 @@ migrate((app) => {
|
|||||||
"type": "select",
|
"type": "select",
|
||||||
"required": true,
|
"required": true,
|
||||||
"presentable": false,
|
"presentable": false,
|
||||||
"options": {
|
|
||||||
"maxSelect": 1,
|
"maxSelect": 1,
|
||||||
"values": [
|
"values": [
|
||||||
"concept_explainer",
|
"concept_explainer",
|
||||||
@@ -37,7 +52,6 @@ migrate((app) => {
|
|||||||
"flashcard_set",
|
"flashcard_set",
|
||||||
"reflection_prompt"
|
"reflection_prompt"
|
||||||
]
|
]
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"system": false,
|
"system": false,
|
||||||
@@ -45,8 +59,7 @@ migrate((app) => {
|
|||||||
"name": "content",
|
"name": "content",
|
||||||
"type": "json",
|
"type": "json",
|
||||||
"required": true,
|
"required": true,
|
||||||
"presentable": false,
|
"presentable": false
|
||||||
"options": {}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"system": false,
|
"system": false,
|
||||||
@@ -55,13 +68,31 @@ migrate((app) => {
|
|||||||
"type": "select",
|
"type": "select",
|
||||||
"required": true,
|
"required": true,
|
||||||
"presentable": false,
|
"presentable": false,
|
||||||
"options": {
|
|
||||||
"maxSelect": 1,
|
"maxSelect": 1,
|
||||||
"values": [
|
"values": [
|
||||||
"draft",
|
"draft",
|
||||||
"published"
|
"published"
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"hidden": false,
|
||||||
|
"id": "autodate_created",
|
||||||
|
"name": "created",
|
||||||
|
"onCreate": true,
|
||||||
|
"onUpdate": false,
|
||||||
|
"presentable": false,
|
||||||
|
"system": true,
|
||||||
|
"type": "autodate"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": false,
|
||||||
|
"id": "autodate_updated",
|
||||||
|
"name": "updated",
|
||||||
|
"onCreate": true,
|
||||||
|
"onUpdate": true,
|
||||||
|
"presentable": false,
|
||||||
|
"system": true,
|
||||||
|
"type": "autodate"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"indexes": [],
|
"indexes": [],
|
||||||
@@ -72,11 +103,6 @@ migrate((app) => {
|
|||||||
"deleteRule": null
|
"deleteRule": null
|
||||||
});
|
});
|
||||||
|
|
||||||
// Since we don't know the exact ID of topics collection safely across instances without looking it up,
|
|
||||||
// we can look it up first.
|
|
||||||
const topicsCollection = app.findCollectionByNameOrId("topics");
|
|
||||||
microLearnings.schema.getFieldByName("topic_id").options.collectionId = topicsCollection.id;
|
|
||||||
|
|
||||||
app.save(microLearnings);
|
app.save(microLearnings);
|
||||||
|
|
||||||
// Create micro_learning_completions collection
|
// Create micro_learning_completions collection
|
||||||
@@ -85,7 +111,22 @@ migrate((app) => {
|
|||||||
"name": "micro_learning_completions",
|
"name": "micro_learning_completions",
|
||||||
"type": "base",
|
"type": "base",
|
||||||
"system": false,
|
"system": false,
|
||||||
"schema": [
|
"fields": [
|
||||||
|
{
|
||||||
|
"autogeneratePattern": "[a-z0-9]{15}",
|
||||||
|
"help": "",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "text_id_mlc",
|
||||||
|
"max": 15,
|
||||||
|
"min": 15,
|
||||||
|
"name": "id",
|
||||||
|
"pattern": "^[a-z0-9]+$",
|
||||||
|
"presentable": false,
|
||||||
|
"primaryKey": true,
|
||||||
|
"required": true,
|
||||||
|
"system": true,
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"system": false,
|
"system": false,
|
||||||
"id": "rel_team_member_id",
|
"id": "rel_team_member_id",
|
||||||
@@ -93,13 +134,11 @@ migrate((app) => {
|
|||||||
"type": "relation",
|
"type": "relation",
|
||||||
"required": true,
|
"required": true,
|
||||||
"presentable": false,
|
"presentable": false,
|
||||||
"options": {
|
"collectionId": teamMembersCollectionId,
|
||||||
"collectionId": "team_members_placeholder",
|
|
||||||
"cascadeDelete": true,
|
"cascadeDelete": true,
|
||||||
"minSelect": null,
|
"minSelect": null,
|
||||||
"maxSelect": 1,
|
"maxSelect": 1,
|
||||||
"displayFields": null
|
"displayFields": null
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"system": false,
|
"system": false,
|
||||||
@@ -108,13 +147,11 @@ migrate((app) => {
|
|||||||
"type": "relation",
|
"type": "relation",
|
||||||
"required": true,
|
"required": true,
|
||||||
"presentable": false,
|
"presentable": false,
|
||||||
"options": {
|
|
||||||
"collectionId": microLearnings.id,
|
"collectionId": microLearnings.id,
|
||||||
"cascadeDelete": true,
|
"cascadeDelete": true,
|
||||||
"minSelect": null,
|
"minSelect": null,
|
||||||
"maxSelect": 1,
|
"maxSelect": 1,
|
||||||
"displayFields": null
|
"displayFields": null
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"system": false,
|
"system": false,
|
||||||
@@ -123,13 +160,11 @@ migrate((app) => {
|
|||||||
"type": "relation",
|
"type": "relation",
|
||||||
"required": true,
|
"required": true,
|
||||||
"presentable": false,
|
"presentable": false,
|
||||||
"options": {
|
"collectionId": topicsCollectionId,
|
||||||
"collectionId": topicsCollection.id,
|
|
||||||
"cascadeDelete": true,
|
"cascadeDelete": true,
|
||||||
"minSelect": null,
|
"minSelect": null,
|
||||||
"maxSelect": 1,
|
"maxSelect": 1,
|
||||||
"displayFields": null
|
"displayFields": null
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"system": false,
|
"system": false,
|
||||||
@@ -138,11 +173,9 @@ migrate((app) => {
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"required": true,
|
"required": true,
|
||||||
"presentable": false,
|
"presentable": false,
|
||||||
"options": {
|
|
||||||
"min": null,
|
"min": null,
|
||||||
"max": null,
|
"max": null,
|
||||||
"pattern": ""
|
"pattern": ""
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"system": false,
|
"system": false,
|
||||||
@@ -151,24 +184,37 @@ migrate((app) => {
|
|||||||
"type": "number",
|
"type": "number",
|
||||||
"required": true,
|
"required": true,
|
||||||
"presentable": false,
|
"presentable": false,
|
||||||
"options": {
|
|
||||||
"min": null,
|
|
||||||
"max": null,
|
|
||||||
"noDecimal": true
|
"noDecimal": true
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"hidden": false,
|
||||||
|
"id": "autodate_created2",
|
||||||
|
"name": "created",
|
||||||
|
"onCreate": true,
|
||||||
|
"onUpdate": false,
|
||||||
|
"presentable": false,
|
||||||
|
"system": true,
|
||||||
|
"type": "autodate"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": false,
|
||||||
|
"id": "autodate_updated2",
|
||||||
|
"name": "updated",
|
||||||
|
"onCreate": true,
|
||||||
|
"onUpdate": true,
|
||||||
|
"presentable": false,
|
||||||
|
"system": true,
|
||||||
|
"type": "autodate"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"indexes": [],
|
"indexes": [],
|
||||||
"listRule": "@request.auth.id != '' && team_member_id.user_id = @request.auth.id",
|
"listRule": "",
|
||||||
"viewRule": "@request.auth.id != '' && team_member_id.user_id = @request.auth.id",
|
"viewRule": "",
|
||||||
"createRule": "@request.auth.id != ''",
|
"createRule": "",
|
||||||
"updateRule": null,
|
"updateRule": "",
|
||||||
"deleteRule": null
|
"deleteRule": ""
|
||||||
});
|
});
|
||||||
|
|
||||||
const teamMembersCollection = app.findCollectionByNameOrId("team_members");
|
|
||||||
completions.schema.getFieldByName("team_member_id").options.collectionId = teamMembersCollection.id;
|
|
||||||
|
|
||||||
app.save(completions);
|
app.save(completions);
|
||||||
|
|
||||||
}, (app) => {
|
}, (app) => {
|
||||||
|
|||||||
@@ -1,19 +1,16 @@
|
|||||||
import { pb } from '../lib/pb';
|
import { pb } from '../lib/pb';
|
||||||
|
import { useApp } from '../store/AppContext';
|
||||||
|
|
||||||
export function useMicroLearningCompletions() {
|
export function useMicroLearningCompletions() {
|
||||||
|
const { state } = useApp();
|
||||||
|
|
||||||
const recordCompletion = async ({ microLearningId, topicId, type, sessionWeek }) => {
|
const recordCompletion = async ({ microLearningId, topicId, type, sessionWeek }) => {
|
||||||
try {
|
try {
|
||||||
const user = pb.authStore.model;
|
const user = state.currentUser;
|
||||||
if (!user) throw new Error("No authenticated user");
|
if (!user) throw new Error("No authenticated user");
|
||||||
|
|
||||||
const teamMemberRec = await pb.collection('team_members').getFirstListItem(`user_id = "${user.id}"`);
|
|
||||||
|
|
||||||
if (!teamMemberRec) {
|
|
||||||
throw new Error("Team member record not found for user.");
|
|
||||||
}
|
|
||||||
|
|
||||||
const record = await pb.collection('micro_learning_completions').create({
|
const record = await pb.collection('micro_learning_completions').create({
|
||||||
team_member_id: teamMemberRec.id,
|
team_member_id: user.id,
|
||||||
micro_learning_id: microLearningId,
|
micro_learning_id: microLearningId,
|
||||||
topic_id: topicId,
|
topic_id: topicId,
|
||||||
type: type,
|
type: type,
|
||||||
@@ -28,11 +25,11 @@ export function useMicroLearningCompletions() {
|
|||||||
|
|
||||||
const getSessionCompletions = async (sessionWeek) => {
|
const getSessionCompletions = async (sessionWeek) => {
|
||||||
try {
|
try {
|
||||||
const teamMemberRec = await pb.collection('team_members').getFirstListItem(`user_id = "${pb.authStore.model.id}"`);
|
const user = state.currentUser;
|
||||||
if (!teamMemberRec) return [];
|
if (!user) return [];
|
||||||
|
|
||||||
const records = await pb.collection('micro_learning_completions').getFullList({
|
const records = await pb.collection('micro_learning_completions').getFullList({
|
||||||
filter: `team_member_id = "${teamMemberRec.id}" && session_week = ${sessionWeek}`
|
filter: `team_member_id = "${user.id}" && session_week = ${sessionWeek}`
|
||||||
});
|
});
|
||||||
return records;
|
return records;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user