session summary endpoint
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
"elysia": "^1.3.5",
|
"elysia": "^1.3.5",
|
||||||
"got": "^14.4.7",
|
"got": "^14.4.7",
|
||||||
"jose": "^6.0.10",
|
"jose": "^6.0.10",
|
||||||
|
"marked": "^16.1.1",
|
||||||
"node-cron": "^4.1.0",
|
"node-cron": "^4.1.0",
|
||||||
"postgres": "^3.4.5",
|
"postgres": "^3.4.5",
|
||||||
},
|
},
|
||||||
@@ -188,6 +189,8 @@
|
|||||||
|
|
||||||
"lowercase-keys": ["lowercase-keys@3.0.0", "", {}, "sha512-ozCC6gdQ+glXOQsveKD0YsDy8DSQFjDTz4zyzEHNV5+JP5D62LmfDZ6o1cycFx9ouG940M5dE8C8CTewdj2YWQ=="],
|
"lowercase-keys": ["lowercase-keys@3.0.0", "", {}, "sha512-ozCC6gdQ+glXOQsveKD0YsDy8DSQFjDTz4zyzEHNV5+JP5D62LmfDZ6o1cycFx9ouG940M5dE8C8CTewdj2YWQ=="],
|
||||||
|
|
||||||
|
"marked": ["marked@16.1.1", "", { "bin": { "marked": "bin/marked.js" } }, "sha512-ij/2lXfCRT71L6u0M29tJPhP0bM5shLL3u5BePhFwPELj2blMJ6GDtD7PfJhRLhJ/c2UwrK17ySVcDzy2YHjHQ=="],
|
||||||
|
|
||||||
"mimic-response": ["mimic-response@4.0.0", "", {}, "sha512-e5ISH9xMYU0DzrT+jl8q2ze9D6eWBto+I8CNpe+VI+K2J/F/k3PdkdTdz4wvGVH4NTpo+NRYTVIuMQEMMcsLqg=="],
|
"mimic-response": ["mimic-response@4.0.0", "", {}, "sha512-e5ISH9xMYU0DzrT+jl8q2ze9D6eWBto+I8CNpe+VI+K2J/F/k3PdkdTdz4wvGVH4NTpo+NRYTVIuMQEMMcsLqg=="],
|
||||||
|
|
||||||
"ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
|
"ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
"elysia": "^1.3.5",
|
"elysia": "^1.3.5",
|
||||||
"got": "^14.4.7",
|
"got": "^14.4.7",
|
||||||
"jose": "^6.0.10",
|
"jose": "^6.0.10",
|
||||||
|
"marked": "^16.1.1",
|
||||||
"node-cron": "^4.1.0",
|
"node-cron": "^4.1.0",
|
||||||
"postgres": "^3.4.5"
|
"postgres": "^3.4.5"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,8 +7,41 @@ import db from "../db";
|
|||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { sessionsTable } from "../db/schema/sessions";
|
import { sessionsTable } from "../db/schema/sessions";
|
||||||
import getCount from "../services/sessions/getCountSessions";
|
import getCount from "../services/sessions/getCountSessions";
|
||||||
|
import { marked, type Tokens } from "marked";
|
||||||
|
|
||||||
const sessionsController = new Elysia({ prefix: "/sessions" })
|
const sessionsController = new Elysia({ prefix: "/sessions" })
|
||||||
|
.put('/summary/:id', async ({ body: { summary, ...metriks }, params: { id } }) => {
|
||||||
|
const paragraphes = marked.lexer(summary).filter(token => token.type === 'paragraph') as Tokens.Paragraph[]
|
||||||
|
const lists = marked.lexer(summary).filter(token => token.type === 'list') as Tokens.List[]
|
||||||
|
|
||||||
|
const introduction = paragraphes[0].text
|
||||||
|
const resume = lists[0].raw
|
||||||
|
const goal = lists[1].items.map(item => item.raw)
|
||||||
|
const presentation = lists[2].items.map(item => item.raw)
|
||||||
|
const finance = lists[3].items.map(item => item.raw)
|
||||||
|
const discussionTone = lists[4].raw
|
||||||
|
const questions = lists[5].items.map(item => item.text)
|
||||||
|
const nextSteps = lists[6].raw
|
||||||
|
const conclusion = paragraphes[1].text
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [session] = await db.update(sessionsTable).set({ summary: { ...metriks, introduction, resume, goal, presentation, finance, discussionTone, questions, nextSteps, conclusion } }).where(eq(sessionsTable.id, id)).returning()
|
||||||
|
return session
|
||||||
|
} catch (error) {
|
||||||
|
console.log((error as Error).message)
|
||||||
|
return status(500, "Internal Server Error")
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
body: t.Object({
|
||||||
|
efficiency: t.Number(),
|
||||||
|
duration: t.Number(),
|
||||||
|
budget: t.Number(),
|
||||||
|
summary: t.String()
|
||||||
|
}),
|
||||||
|
params: t.Object({
|
||||||
|
id: t.String(),
|
||||||
|
})
|
||||||
|
})
|
||||||
.use(authMiddleware)
|
.use(authMiddleware)
|
||||||
.get("/", ({ auth, query }) => getSessions(auth, query), {
|
.get("/", ({ auth, query }) => getSessions(auth, query), {
|
||||||
query: t.Partial(
|
query: t.Partial(
|
||||||
@@ -75,11 +108,11 @@ const sessionsController = new Elysia({ prefix: "/sessions" })
|
|||||||
updateSession(
|
updateSession(
|
||||||
params.id,
|
params.id,
|
||||||
body.status as
|
body.status as
|
||||||
| "starting"
|
| "starting"
|
||||||
| "started"
|
| "started"
|
||||||
| "restarting"
|
| "restarting"
|
||||||
| "ending"
|
| "ending"
|
||||||
| "ended"
|
| "ended"
|
||||||
),
|
),
|
||||||
{
|
{
|
||||||
params: t.Object({
|
params: t.Object({
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import {
|
|||||||
varchar,
|
varchar,
|
||||||
uniqueIndex,
|
uniqueIndex,
|
||||||
integer,
|
integer,
|
||||||
|
text,
|
||||||
|
json,
|
||||||
} from "drizzle-orm/pg-core";
|
} from "drizzle-orm/pg-core";
|
||||||
import { companiesTable } from "./companies";
|
import { companiesTable } from "./companies";
|
||||||
import { managersTable } from "./managers";
|
import { managersTable } from "./managers";
|
||||||
@@ -14,6 +16,7 @@ import { clientsTable } from "./clients";
|
|||||||
import { appsTable } from "./apps";
|
import { appsTable } from "./apps";
|
||||||
import { sql } from "drizzle-orm";
|
import { sql } from "drizzle-orm";
|
||||||
import { commentsTable } from "./comments";
|
import { commentsTable } from "./comments";
|
||||||
|
import type { Summary } from "../../types/summary";
|
||||||
|
|
||||||
export const sessionsTable = pgTable(
|
export const sessionsTable = pgTable(
|
||||||
"sessions",
|
"sessions",
|
||||||
@@ -25,6 +28,7 @@ export const sessionsTable = pgTable(
|
|||||||
.notNull()
|
.notNull()
|
||||||
.default("starting"),
|
.default("starting"),
|
||||||
pid: integer("pid"),
|
pid: integer("pid"),
|
||||||
|
summary: json("summary").$type<Summary>(),
|
||||||
appId: uuid("app_id")
|
appId: uuid("app_id")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => appsTable.id, { onDelete: "cascade" }),
|
.references(() => appsTable.id, { onDelete: "cascade" }),
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
export interface Summary {
|
||||||
|
efficiency: number;
|
||||||
|
duration: number;
|
||||||
|
budget: number;
|
||||||
|
introduction: string;
|
||||||
|
resume: string;
|
||||||
|
goal: string[];
|
||||||
|
presentation: string[];
|
||||||
|
finance: string[];
|
||||||
|
discussionTone: string
|
||||||
|
questions: string[];
|
||||||
|
nextSteps: string;
|
||||||
|
conclusion: string;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user