Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion server/.env.example

This file was deleted.

35 changes: 30 additions & 5 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dependencies": {
"@fastify/session": "^11.1.1",
"@fastify/swagger": "^9.6.1",
"@fastify/swagger-ui": "^5.2.4",
"@prisma/adapter-pg": "^7.3.0",
Expand Down
6 changes: 6 additions & 0 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ model Question {
@@index([roleId])
}

mode ScrumMasterQuestion {
id Int @id @default(autoincrement())
prompt String
answer String
}

model Choice {
id String @id @default(cuid())
questionId String
Expand Down
11 changes: 10 additions & 1 deletion server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import { rolesRoutes } from './routes/roles';
import { baseResponseSchema } from "./schemas/builders";
import { constructResponse } from "./utilities/common";
import { questionsRoutes } from "./routes/questions";
import { fastifyCookie } from "@fastify/cookie";
import { fastifySession } from "@fastify/session";


// import pkg from "../../package.json";

const port = Number(process.env.PORT || 0) || 4000
const port = Number(process.env.PORT || 0) || 4000;
const host = ("RENDER" in process.env) ? `0.0.0.0` : `localhost`;

const setup = async () => {
Expand All @@ -34,6 +38,11 @@ const setup = async () => {
await server.register(rolesRoutes, { prefix: "/api/roles" });
await server.register(questionsRoutes, { prefix: "/api/questions" });

// user sesion
await server.register(fastifyCookie);
await server.register(fastifySession, {secret: 'a secret with minimum length of 32 characters'});


server.get("/", {
schema: {
tags: ["Base"],
Expand Down
68 changes: 68 additions & 0 deletions server/src/routes/questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,74 @@ export const questionsRoutes: FastifyPluginAsync = async (server) => {
}
);

server.get(
"/getNextQuestion",
{ schema: getQuestionSchema },
async (request, reply) => {

// this currently only applies to one role, want to double check something first before i fully implement this
// i'm still getting familair with typscript will read the handbook and double back to fix any issue here

try {
const currentIndex = request.session.get("currentQuestion") ? request.session.get("currentQuestion") : 0;
const data = await QuestionService.getQuestion_v2(currentIndex);

// update current session index
request.session.set("currentIndex", currentIndex + 1 );

return constructResponse({
reply,
code: 200,
apiObject: API_OBJECTS.Question,
message: STRINGS.Success,
data,
});
} catch (error) {
return constructResponse({
reply,
code: 500,
apiObject: API_OBJECTS.Question,
message: ERROR_MESSAGES.InternalServerError,
data: error,
});
}


}
);

server.get(
"/getNextQuestionAnswer",
{ schema: getQuestionSchema },
async (request, reply) => {
try {
const currentIndex = request.session.get("currentQuestion") ? request.session.get("currentQuestion") : 0;
// todo: this should throw an error if currentIndex is undefined (above)

const data = await QuestionService.getQuestion_v2(currentIndex);
const answer = data.answer;

return constructResponse({
reply,
code: 200,
apiObject: API_OBJECTS.Question,
message: STRINGS.Success,
answer,
});


} catch (error) {
return constructResponse({
reply,
code: 500,
apiObject: API_OBJECTS.Question,
message: ERROR_MESSAGES.InternalServerError,
data: error,
});
}
}
);

// server.post(
// "/",
// { schema: createQuestionSchema },
Expand Down
13 changes: 12 additions & 1 deletion server/src/routes/roles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { API_OBJECTS } from "@/constants";
import { getRoleSchema, getRolesSchema } from "@/schemas/roles";
import { getRoleSchema, getRolesSchema, setRoleSchema } from "@/schemas/roles";
import { RoleService } from "@/services/roles.service";
import { constructResponse } from "@/utilities";
import { FastifyPluginAsync } from "fastify";
Expand Down Expand Up @@ -69,4 +69,15 @@ export const rolesRoutes: FastifyPluginAsync = async (fastify) => {
}
}
);

fastify.post("/setRole", {schema: setRoleSchema}, (request, reply) => {
request.session.set("role", request.body);
return constructResponse({
reply,
message: "Role Set successfully",
data: "",
code: 200,
apiObject: API_OBJECTS.Role
});
});
}
9 changes: 9 additions & 0 deletions server/src/schemas/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ export const getRoleSchema = {
}
} as const;

export const setRoleSchema = {
tags: [ "Roles"],
description: "Role has been set",
body: {},
response: {
200: constructSuccessResponse(roleSchema)
}
}

// POST /roles - Create role
export const createRoleSchema = {
tags: ["Roles"],
Expand Down
8 changes: 8 additions & 0 deletions server/src/services/questions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ export class QuestionService {
return question;
};

static getQuestion_v2 = async (currentIndex: number) => {

// to do update this to add account for different user roles
const question = await prisma.crummasterquestion.findUnique({
where: {id: currentIndex}
})
}

static getQuestionsByRole = async (
roleKey: string,
params: PaginationParams
Expand Down
1 change: 1 addition & 0 deletions server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"module": "esnext",
"target": "es2023",
"moduleResolution": "bundler",
"esModuleInterop": true,
"types": [],
// For nodejs:
// "lib": ["esnext"],
Expand Down