Skip to content

Commit 511ceb1

Browse files
authored
use usrCrsDb interface to update settings (#666)
2 parents dc649a0 + 310fd1e commit 511ceb1

File tree

23 files changed

+313
-293
lines changed

23 files changed

+313
-293
lines changed

.github/workflows/build-express.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ jobs:
4343
- name: Build common package
4444
run: yarn workspace @vue-skuilder/common build
4545

46+
- name: Build db package
47+
run: yarn workspace @vue-skuilder/db build
48+
4649
- name: Build and test express package
4750
run: |
4851
yarn workspace @vue-skuilder/express build

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "test-couch"]
22
path = test-couch
3-
url = http://github.com/nilock/skuilder-test-db
3+
url = http://github.com/patched-network/skuilder-test-db

packages/common/src/ENVIRONMENT_VARS.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,43 @@ declare global {
3838

3939
// Default fallback values if all else fails
4040
const defaultEnv: Environment = {
41-
COUCHDB_SERVER_URL: 'default:5984/',
41+
COUCHDB_SERVER_URL: 'localhost:5984/',
4242
COUCHDB_SERVER_PROTOCOL: 'http',
4343
EXPRESS_SERVER_URL: 'localhost:3000/',
4444
EXPRESS_SERVER_PROTOCOL: 'http',
4545
DEBUG: false,
4646
MOCK: false,
4747
};
4848

49-
// Get environment from global or default
50-
const ENV: Environment =
51-
typeof window !== 'undefined' && window.__SKUILDER_ENV__
52-
? { ...defaultEnv, ...window.__SKUILDER_ENV__ }
53-
: defaultEnv;
49+
// Determine if we're in browser or Node environment
50+
const isBrowser = typeof window !== 'undefined';
5451

55-
// Log the initialized environment
56-
console.log('ENV initialized:', ENV);
52+
// Function to get environment from Node process.env
53+
function getNodeEnv(): Environment {
54+
console.log(`Process.env: ${JSON.stringify(process.env)}`);
55+
return {
56+
COUCHDB_SERVER_URL: process.env.COUCHDB_SERVER || defaultEnv.COUCHDB_SERVER_URL,
57+
COUCHDB_SERVER_PROTOCOL: (process.env.COUCHDB_PROTOCOL ||
58+
defaultEnv.COUCHDB_SERVER_PROTOCOL) as ProtocolString,
59+
EXPRESS_SERVER_URL: process.env.EXPRESS_SERVER || defaultEnv.EXPRESS_SERVER_URL,
60+
EXPRESS_SERVER_PROTOCOL: (process.env.EXPRESS_PROTOCOL ||
61+
defaultEnv.EXPRESS_SERVER_PROTOCOL) as ProtocolString,
62+
DEBUG: process.env.DEBUG === 'true' || defaultEnv.DEBUG,
63+
MOCK: process.env.MOCK === 'true' || defaultEnv.MOCK,
64+
};
65+
}
66+
67+
// Get environment based on runtime context
68+
let ENV: Environment;
69+
70+
if (isBrowser) {
71+
// Browser environment - use window.__SKUILDER_ENV__ if available
72+
ENV = window.__SKUILDER_ENV__ ? { ...defaultEnv, ...window.__SKUILDER_ENV__ } : defaultEnv;
73+
console.log('Browser ENV initialized:', ENV);
74+
} else {
75+
// Node.js environment - use process.env
76+
ENV = getNodeEnv();
77+
console.log('Node ENV initialized:', ENV);
78+
}
5779

5880
export default ENV;

packages/courses/src/piano/utility/MidiConfig.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ import { defineComponent, ref, watch, onMounted } from 'vue';
8181
import { alertUser } from '@vue-skuilder/common-ui';
8282
import SkMidi from './midi';
8383
import { Status } from '@vue-skuilder/common';
84-
import { UserDBInterface } from '@vue-skuilder/db';
84+
import { UserDBInterface, getDataLayer } from '@vue-skuilder/db';
8585
import { InputEventNoteon } from 'webmidi';
8686
import PianoRangeVisualizer from './PianoRangeVisualizer.vue';
8787
@@ -437,7 +437,10 @@ export default defineComponent({
437437
438438
const saveSettings = async () => {
439439
updatePending.value = true;
440-
await props.user.updateCourseSettings(props._id, [
440+
441+
const usrCrsDB = await getDataLayer().getUserDB().getCourseInterface(props._id);
442+
443+
usrCrsDB.updateCourseSettings([
441444
{
442445
key: 'midiinput',
443446
value: selectedInput.value,

packages/db/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@nilock2/pouchdb-authentication": "^1.0.2",
3131
"@vue-skuilder/common": "workspace:*",
3232
"moment": "^2.29.4",
33-
"pouchdb-browser": "^9.0.0",
33+
"pouchdb": "^9.0.0",
3434
"pouchdb-find": "^9.0.0"
3535
},
3636
"devDependencies": {

packages/db/src/core/interfaces/adminDB.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ClassroomConfig } from '@vue-skuilder/common';
1+
import { ClassroomConfig, CourseConfig } from '@vue-skuilder/common';
22

33
/**
44
* Admin functionality
@@ -12,7 +12,7 @@ export interface AdminDBInterface {
1212
/**
1313
* Get all courses
1414
*/
15-
getCourses(): Promise<PouchDB.Core.Document<{}>[]>;
15+
getCourses(): Promise<CourseConfig[]>;
1616

1717
/**
1818
* Remove a course

packages/db/src/impl/pouch/adminDB.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
import pouch from 'pouchdb-browser';
1+
import pouch from 'pouchdb';
22
import { ENV } from '@vue-skuilder/common';
3-
import { pouchDBincludeCredentialsConfig, getStartAndEndKeys } from '.';
4-
import { getCourseList, removeCourse } from './courseDB';
3+
import {
4+
pouchDBincludeCredentialsConfig,
5+
getStartAndEndKeys,
6+
getCredentialledCourseConfig,
7+
updateCredentialledCourseConfig,
8+
} from '.';
59
import { TeacherClassroomDB, ClassroomLookupDB } from './classroomDB';
610
import { PouchError } from './types';
711

812
import { AdminDBInterface } from '@/core';
13+
import CourseLookup from './courseLookupDB';
914

1015
export class AdminDB implements AdminDBInterface {
1116
private usersDB!: PouchDB.Database;
@@ -27,12 +32,31 @@ export class AdminDB implements AdminDBInterface {
2732
})
2833
).rows.map((r) => r.doc!);
2934
}
35+
3036
public async getCourses() {
31-
return (await getCourseList()).rows.map((r) => r.doc!);
37+
const list = await CourseLookup.allCourses();
38+
return await Promise.all(
39+
list.map((c) => {
40+
return getCredentialledCourseConfig(c._id);
41+
})
42+
);
3243
}
3344
public async removeCourse(id: string) {
34-
return await removeCourse(id);
45+
// remove the indexer
46+
const delResp = await CourseLookup.delete(id);
47+
48+
// set the 'CourseConfig' to 'deleted'
49+
const cfg = await getCredentialledCourseConfig(id);
50+
cfg.deleted = true;
51+
const isDeletedResp = await updateCredentialledCourseConfig(id, cfg);
52+
53+
return {
54+
ok: delResp.ok && isDeletedResp.ok,
55+
id: delResp.id,
56+
rev: delResp.rev,
57+
};
3558
}
59+
3660
public async getClassrooms() {
3761
// const joincodes =
3862
const uuids = (

packages/db/src/impl/pouch/classroomDB.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from '@/core/interfaces/contentSource';
66
import { ClassroomConfig, ENV } from '@vue-skuilder/common';
77
import moment from 'moment';
8-
import pouch from 'pouchdb-browser';
8+
import pouch from 'pouchdb';
99
import {
1010
getCourseDB,
1111
getStartAndEndKeys,

packages/db/src/impl/pouch/courseAPI.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pouch from 'pouchdb-browser';
1+
import pouch from 'pouchdb';
22
import { pouchDBincludeCredentialsConfig } from '.';
33
import { ENV } from '@vue-skuilder/common';
44
// import { DataShape } from '../..base-course/Interfaces/DataShape';
@@ -136,16 +136,17 @@ async function addCard(
136136
return card;
137137
}
138138

139-
export async function getCredentialledCourseConfig(courseID: string) {
140-
const db = getCourseDB(courseID);
141-
const ret = await db.get<CourseConfig>('CourseConfig');
142-
ret.courseID = courseID;
143-
console.log(`Returning corse config:
144-
145-
${JSON.stringify(ret)}
146-
`);
147-
148-
return ret;
139+
export async function getCredentialledCourseConfig(courseID: string): Promise<CourseConfig> {
140+
try {
141+
const db = getCourseDB(courseID);
142+
const ret = await db.get<CourseConfig>('CourseConfig');
143+
ret.courseID = courseID;
144+
console.log(`Returning course config: ${JSON.stringify(ret)}`);
145+
return ret;
146+
} catch (e) {
147+
console.error(`Error fetching config for ${courseID}:`, e);
148+
throw e;
149+
}
149150
}
150151

151152
/**

0 commit comments

Comments
 (0)