@eeplatform/basic-edu 1.10.38 → 1.10.40
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/.github/workflows/publish.yml +7 -8
- package/CHANGELOG.md +12 -0
- package/CLAUDE.md +106 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -17,23 +17,22 @@ jobs:
|
|
|
17
17
|
runs-on: ubuntu-latest
|
|
18
18
|
steps:
|
|
19
19
|
- uses: actions/checkout@v4
|
|
20
|
+
with:
|
|
21
|
+
fetch-depth: 0
|
|
20
22
|
|
|
21
23
|
- uses: actions/setup-node@v4
|
|
22
24
|
with:
|
|
23
25
|
node-version: 20.x
|
|
24
|
-
cache: "yarn"
|
|
25
|
-
cache-dependency-path: yarn.lock
|
|
26
|
-
|
|
27
|
-
- run: yarn install --immutable # Install dependencies with immutable lockfile
|
|
26
|
+
cache: "yarn"
|
|
27
|
+
cache-dependency-path: yarn.lock
|
|
28
28
|
|
|
29
|
-
-
|
|
30
|
-
run: |
|
|
31
|
-
echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}' > ~/.npmrc
|
|
29
|
+
- run: yarn install --immutable
|
|
32
30
|
|
|
33
31
|
- name: Create Release Pull Request or Publish
|
|
34
32
|
id: changesets
|
|
35
33
|
uses: changesets/action@v1
|
|
36
34
|
with:
|
|
37
|
-
publish: yarn release
|
|
35
|
+
publish: yarn release
|
|
38
36
|
env:
|
|
39
37
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
38
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/CHANGELOG.md
CHANGED
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# server-core-module (`@goweekdays/core`)
|
|
2
|
+
|
|
3
|
+
Shared server module exported as a package consumed by all app servers.
|
|
4
|
+
Built with Express + MongoDB (Atlas) + TypeScript.
|
|
5
|
+
|
|
6
|
+
## Resource Layer Pattern
|
|
7
|
+
|
|
8
|
+
Each resource lives under `src/resources/<resource-name>/` and follows this structure:
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
resource-name/
|
|
12
|
+
resource.model.ts # Types and validation schema
|
|
13
|
+
resource.repository.ts # Direct database interaction
|
|
14
|
+
resource.service.ts # Business logic (optional — see below)
|
|
15
|
+
resource.controller.ts # API request handler
|
|
16
|
+
index.ts # Barrel export
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### `.model.ts`
|
|
20
|
+
|
|
21
|
+
Defines the TypeScript type and Joi validation schema for the resource. This is the source of truth for the shape of the data.
|
|
22
|
+
|
|
23
|
+
### `.repository.ts`
|
|
24
|
+
|
|
25
|
+
Contains all functions that directly interact with the database (MongoDB). No business logic here — only reads and writes.
|
|
26
|
+
|
|
27
|
+
### `.service.ts`
|
|
28
|
+
|
|
29
|
+
Builds business logic by composing repository functions and third-party integrations (e.g. hashing, email, S3, transactions). Never accesses the database directly — all DB interaction goes through the repository. **This layer is optional** — if a resource only needs basic CRUD with no business logic, a service file is not required.
|
|
30
|
+
|
|
31
|
+
### `.controller.ts`
|
|
32
|
+
|
|
33
|
+
Handles incoming API requests. Validates the request input, then delegates to the service layer if business logic exists, or calls the repository directly if the resource has no service.
|
|
34
|
+
|
|
35
|
+
### `index.ts`
|
|
36
|
+
|
|
37
|
+
Re-exports all layers so consumers can import from the resource folder directly.
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
export * from "./user.model";
|
|
41
|
+
export * from "./user.repository";
|
|
42
|
+
export * from "./user.service";
|
|
43
|
+
export * from "./user.controller";
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Naming Conventions
|
|
49
|
+
|
|
50
|
+
| Layer | Pattern | Example |
|
|
51
|
+
| ---------- | --------------------------- | ---------------------------------------------------- |
|
|
52
|
+
| File | `<resource>.<layer>.ts` | `user.model.ts`, `finance.journal.config.service.ts` |
|
|
53
|
+
| Type | `T<Resource>` | `TUser`, `TJobPost` |
|
|
54
|
+
| Schema | `schema<Resource>` | `schemaUser`, `schemaJobPost` |
|
|
55
|
+
| Model fn | `model<Resource>()` | `modelUser()`, `modelJobPost()` |
|
|
56
|
+
| Repository | `use<Resource>Repo()` | `useUserRepo()`, `useOrgRepo()` |
|
|
57
|
+
| Service | `use<Resource>Service()` | `useUserService()`, `useOrgService()` |
|
|
58
|
+
| Controller | `use<Resource>Controller()` | `useUserController()` |
|
|
59
|
+
|
|
60
|
+
Multi-word resource names use dot notation in file names: `finance.journal.config.model.ts`, `job.post.repository.ts`.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Error Handling
|
|
65
|
+
|
|
66
|
+
Always use the typed error classes from `@eeplatform/nodejs-utils` — never throw a generic `new Error()`.
|
|
67
|
+
|
|
68
|
+
- `BadRequestError` — invalid input or a violated business rule
|
|
69
|
+
- `NotFoundError` — resource does not exist
|
|
70
|
+
- `InternalServerError` — unexpected DB or system failure
|
|
71
|
+
- `AppError` — base class; use `instanceof AppError` in catch blocks to re-throw typed errors as-is
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Controller Input Extraction
|
|
76
|
+
|
|
77
|
+
Validate the entire `req.body` against a Joi schema to ensure no unexpected keys are passed. Extract only the fields you need after validation.
|
|
78
|
+
|
|
79
|
+
1. Define a Joi schema that describes exactly the expected shape
|
|
80
|
+
2. Validate `req.body` (or `req.params` / `req.query`) against it — reject if invalid
|
|
81
|
+
3. Destructure only the needed fields from the validated result
|
|
82
|
+
4. Delegate to the service or repository
|
|
83
|
+
|
|
84
|
+
This prevents unexpected or extra fields from leaking into the database.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Transactions
|
|
89
|
+
|
|
90
|
+
Use a MongoDB session whenever a service function writes to more than one collection. The pattern is always:
|
|
91
|
+
|
|
92
|
+
1. Start session and transaction
|
|
93
|
+
2. Pass `session` down to every repo call
|
|
94
|
+
3. Commit on success, abort on error, and always end the session in `finally`
|
|
95
|
+
|
|
96
|
+
Transactions belong in the service layer only — never in a controller or repository.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## What Not To Do
|
|
101
|
+
|
|
102
|
+
- **No business logic in controllers** — controllers only handle HTTP input/output and delegate
|
|
103
|
+
- **No direct DB access in controllers or services** — all DB interaction belongs in the repository only
|
|
104
|
+
- **No generic `Error` throws** — use the typed error classes above
|
|
105
|
+
- **No Zod** — validation is done with Joi throughout this module
|
|
106
|
+
- **No extra fields into the DB** — always validate the full request body before using any of it
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -6521,7 +6521,7 @@ function useSchoolRepo() {
|
|
|
6521
6521
|
cacheKeyOptions.prefix = prefix;
|
|
6522
6522
|
}
|
|
6523
6523
|
if (search) {
|
|
6524
|
-
query.$text = { $search: search };
|
|
6524
|
+
query.$text = { $search: `"${search}"` };
|
|
6525
6525
|
cacheKeyOptions.search = search;
|
|
6526
6526
|
}
|
|
6527
6527
|
const cacheKey = (0, import_nodejs_utils24.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
@@ -39975,7 +39975,7 @@ var allowedSectionStudentStatuses = [
|
|
|
39975
39975
|
];
|
|
39976
39976
|
var schemaSectionStudent = import_joi33.default.object({
|
|
39977
39977
|
_id: import_joi33.default.string().hex().optional().allow(null, ""),
|
|
39978
|
-
lrn: import_joi33.default.string().
|
|
39978
|
+
lrn: import_joi33.default.string().optional().allow(null, ""),
|
|
39979
39979
|
school: import_joi33.default.string().hex().required(),
|
|
39980
39980
|
schoolName: import_joi33.default.string().optional().allow(null, ""),
|
|
39981
39981
|
section: import_joi33.default.string().hex().required(),
|
|
@@ -42380,9 +42380,6 @@ function useSectionService() {
|
|
|
42380
42380
|
if (!student._id) {
|
|
42381
42381
|
throw new import_nodejs_utils66.BadRequestError("Learner ID is missing.");
|
|
42382
42382
|
}
|
|
42383
|
-
if (!student.learnerInfo.lrn) {
|
|
42384
|
-
throw new import_nodejs_utils66.BadRequestError("Learner LRN is missing.");
|
|
42385
|
-
}
|
|
42386
42383
|
const existingStudent = await getStudent({
|
|
42387
42384
|
student: student._id.toString(),
|
|
42388
42385
|
schoolYear: value.schoolYear,
|