fix(exercise): persist completion policy and improve dev build workflow (#754)
* fix(exercise): persist completion policy and pass threshold on save buildExerciseUpdateFields accepted completionPolicy and passThreshold in the validation schema but never mapped them to the database update, so exercise settings appeared to save while reverting on refresh. Co-authored-by: Rotimi Best <rotimi-best@users.noreply.github.com> * fix(db): build workspace deps before compiling @cio/db imports @cio/utils/notifications, which only exists after @cio/utils is built. Building db in isolation failed when utils dist was missing or stale. - Add a db prebuild step for question-types, utils, and email - Clean dist and tsbuildinfo before utils and email builds so incremental tsc cannot skip emission after dist was removed Co-authored-by: Rotimi Best <rotimi-best@users.noreply.github.com> * chore(dev): build api workspace deps before api:dev Run turbo build for @cio/api and @cio/jobs-worker dependencies before starting the dev servers, so missing dist/ folders do not break startup. Co-authored-by: Rotimi Best <rotimi-best@users.noreply.github.com> * feat(course): improve exercise progression grading UX --------- Co-authored-by: Rotimi Best <rotimi-best@users.noreply.github.com>
This commit is contained in:
co-authored by
Rotimi Best
parent
fdc19aac41
commit
bfafc685e0
@@ -1,7 +1,7 @@
|
||||
import * as schema from '@db/schema';
|
||||
|
||||
import { TGroupmember, TNewGroupmember } from '@db/types';
|
||||
import { and, eq, or } from 'drizzle-orm';
|
||||
import { and, eq, isNull, or } from 'drizzle-orm';
|
||||
|
||||
import { ROLE } from '@cio/utils/constants';
|
||||
import { db } from '@db/drizzle';
|
||||
@@ -325,6 +325,25 @@ export async function setMemberCertificateEarned(memberId: string, earnedAt: str
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Atomically claims the certificate for a member: only succeeds if it was not earned yet.
|
||||
* Returns true when this caller won the claim, so concurrent evaluations issue the
|
||||
* certificate (and downstream email) exactly once.
|
||||
*/
|
||||
export async function claimMemberCertificateEarned(memberId: string, earnedAt: string): Promise<boolean> {
|
||||
try {
|
||||
const updated = await db
|
||||
.update(schema.groupmember)
|
||||
.set({ certificateEarnedAt: earnedAt })
|
||||
.where(and(eq(schema.groupmember.id, memberId), isNull(schema.groupmember.certificateEarnedAt)))
|
||||
.returning({ id: schema.groupmember.id });
|
||||
return updated.length > 0;
|
||||
} catch (error) {
|
||||
console.error('claimMemberCertificateEarned error:', error);
|
||||
throw new Error(`Failed to claim certificate earned: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Records that the certification congratulations email was sent.
|
||||
*/
|
||||
|
||||
@@ -996,7 +996,7 @@ export const lesson = pgTable(
|
||||
callUrl: text('call_url'),
|
||||
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
||||
order: bigint({ mode: 'number' }),
|
||||
isUnlocked: boolean('is_unlocked').default(false),
|
||||
isUnlocked: boolean('is_unlocked').default(true),
|
||||
completionPolicy: varchar('completion_policy').default('manual').notNull(),
|
||||
videoWatchThreshold: integer('video_watch_threshold').default(95),
|
||||
videos: jsonb().default([]).$type<
|
||||
|
||||
Reference in New Issue
Block a user