C2 — Volunteer profile sliders (self_comfort; verified_level untouched)

Adds the user_skills record and slider save path so a volunteer can rate
their own comfort without ever moving the verified level, which stays
C3's to write.
This commit is contained in:
Tiel Coder
2026-11-18 04:14:06 +00:00
parent d74232de60
commit a77f47d5bd
8 changed files with 2287 additions and 5 deletions
+49 -5
View File
@@ -459,14 +459,57 @@ export const positionSkills = pgTable(
],
);
/* ------------------------------------------------- user_skills (C2) */
/**
* A volunteer's competency record for one skill (ARCHITECTURE §4.3). The two
* numbers that matter — `self_comfort` (the volunteer's own 0-100 rating, the
* signal) and `verified_level` (the mentor/admin gate) — are independent: a
* volunteer rating their comfort never moves the verified level. C2 owns the
* self_comfort path; C3 owns verified_level (skill_assessments).
*/
export const userSkills = pgTable(
"user_skills",
{
id: text("id").primaryKey(),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
skillId: text("skill_id")
.notNull()
.references(() => skills.id, { onDelete: "cascade" }),
/** 0..100 — the volunteer's own rating; null until they rate it. */
selfComfort: integer("self_comfort"),
/** When they last rated their own comfort. */
selfRatedAt: timestamp("self_rated_at", { mode: "date", withTimezone: true }),
/** Verified level — the gate. Set by a mentor/admin, never by self-report. */
verifiedLevel: text("verified_level", { enum: SKILL_LEVELS })
.notNull()
.default("none"),
/** Mentor/admin who signed off. */
verifiedBy: text("verified_by"),
verifiedAt: timestamp("verified_at", { mode: "date", withTimezone: true }),
/** Volunteer agrees to teach this skill (C5 mentor designation). */
mentorOptIn: boolean("mentor_opt_in").notNull().default(false),
/** Maintained by the system on assignment completion — never entered by hand. */
lastServedOn: date("last_served_on"),
notes: text("notes"),
},
(table) => [
// Unique (user_id, skill_id) — one competency record per user per skill.
uniqueIndex("user_skills_user_skill_idx").on(table.userId, table.skillId),
index("user_skills_skill_idx").on(table.skillId),
],
);
/* ------------------------------------------------------------- relations */
/**
* Skills compose from the four catalog tables (B3). `skills` and
* `position_skills` are intentionally excluded from `relations`: their FK
* columns are themselves part of composite/unique keys, which trips Drizzle
* 0.45.4's `one()` typing (see the B2 note). Queried directly until a working
* eager-load pattern exists — the grid render in I2 pre-resolves the joins.
* Skills compose from the four catalog tables (B3). `skills`,
* `position_skills` and `user_skills` are intentionally excluded from `relations`:
* their FK columns are themselves part of composite/unique keys, which trips
* Drizzle 0.45.4's `one()` typing (see the B2 note). Queried directly until a
* working eager-load pattern exists — the grid render in I2 pre-resolves the joins.
*/
export const usersRelations = relations(users, ({ many }) => ({
assignments: many(assignments),
@@ -544,6 +587,7 @@ export const schema = {
functions,
skills,
positionSkills,
userSkills,
};
export type Schema = typeof schema;