feat(api): ship + research endpoints queue tasks with lead + helpers; mission accept is instant and free (#44)
CI / build + unit + e2e (pull_request) Failing after 3m58s
CI / build + unit + e2e (pull_request) Failing after 3m58s
This commit is contained in:
@@ -70,6 +70,23 @@ export async function resolveResearchTask(db: GameDb, task: Task): Promise<void>
|
||||
await persist(db)
|
||||
}
|
||||
|
||||
// The research pre-checks, extracted for the queueing route (5a(ii)): the same codes and
|
||||
// messages as researchTech — unknown tech (404), already researched (409), missing prereqs
|
||||
// (409, naming what is missing). The cost check stays out: the queueing path deducts at
|
||||
// queue time (queueTask) and the research lands when the task completes on the tick.
|
||||
export async function checkResearchPreconditions(db: GameDb, techId: number): Promise<void> {
|
||||
await ensureSave(db)
|
||||
const rows = await db.db.select().from(schema.tech)
|
||||
const target = rows.find((t) => t.id === techId)
|
||||
if (!target) throw new ResearchError(404, `Unknown tech ${techId}`)
|
||||
|
||||
const def = TECHS.find((t) => t.slug === target.slug)!
|
||||
const researched = await researchedSlugs(db)
|
||||
if (researched.has(def.slug)) throw new ResearchError(409, `${def.name} is already researched`)
|
||||
const missing = def.prereqs.filter((p) => !researched.has(p)).map((slug) => TECHS.find((t) => t.slug === slug)?.name ?? slug)
|
||||
if (missing.length > 0) throw new ResearchError(409, `${def.name} requires ${missing.join(' and ')} first`)
|
||||
}
|
||||
|
||||
// Research one tech: validates prerequisites (409, naming what is missing) and the cost (422),
|
||||
// spends it from the cargo hold, then delegates the unlock to the resolver at the new turn.
|
||||
export async function researchTech(db: GameDb, techId: number): Promise<TechDto[]> {
|
||||
|
||||
Reference in New Issue
Block a user