-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreflexion.ts
More file actions
73 lines (65 loc) · 1.92 KB
/
reflexion.ts
File metadata and controls
73 lines (65 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { z } from "zod";
import axios from "axios";
import { router, publicProcedure } from "../trpc";
import { env } from "../../../env/server.mjs";
import { randUser, randBetweenDate } from "@ngneat/falso";
import { DateTime } from "luxon";
const relfexionApi = axios.create({
baseURL: env.REFLEXION_BASE_URL,
headers: {
Authorization: `Bearer ${env.REFLEXION_API_KEY}`,
},
});
type UserSessionResponse = {
userSessionToken: string;
};
type userSessionTokenCheckResponse =
| {
completed: false;
}
| {
completed: true;
assessmentType: string;
completedTime: number;
cognitions: {
name: "prioritization";
rawScore: number;
rawUnits: string;
rfxnScore: number;
}[];
};
export const reflexionRouter = router({
createNewRandomSession: publicProcedure.mutation(async ({}) => {
const randomUser = randUser();
const birthDate = randBetweenDate({
from: DateTime.fromISO("1960-01-01").toJSDate(),
to: DateTime.fromISO("2004-01-01").toJSDate(),
});
const userSessionResponse = await relfexionApi.post<UserSessionResponse>(
"/org/usersession",
{
userID: randomUser.id,
birthDate: DateTime.fromJSDate(birthDate).toFormat("yyyy-MM-dd"),
assessmentType: "ai.io_aws",
showVideos: false,
showProgressPage: false,
showSpiderGraph: false,
showInstructions: false,
}
);
return {
userId: randomUser.id,
birthDate: birthDate,
userSessionToken: userSessionResponse.data.userSessionToken,
};
}),
checkUserSession: publicProcedure
.input(z.object({ userSessionToken: z.string() }))
.query(async ({ input }) => {
const userSessionTokenCheckResponse =
await relfexionApi.get<userSessionTokenCheckResponse>(
`/org/usersession/${input.userSessionToken}`
);
return userSessionTokenCheckResponse.data;
}),
});