Skip to content

Commit

Permalink
Merge pull request #405 from Peppermint-Lab/next
Browse files Browse the repository at this point in the history
next
  • Loading branch information
potts99 authored Nov 13, 2024
2 parents b4c66de + c835045 commit 44256d1
Show file tree
Hide file tree
Showing 48 changed files with 8,649 additions and 2,042 deletions.
9 changes: 6 additions & 3 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"@types/bcrypt": "^5.0.0",
"@types/email-reply-parser": "^1",
"@types/formidable": "^3.4.5",
"@types/imap": "^0.8.42",
"@types/jsonwebtoken": "^8.5.8",
"@types/mailparser": "^3.4.5",
"@types/node": "^17.0.23",
"@types/nodemailer": "^6.4.14",
"@types/passport-local": "^1.0.35",
Expand All @@ -30,18 +32,19 @@
"dependencies": {
"@azure/identity": "^4.5.0",
"@fastify/cookie": "^9.0.4",
"@fastify/cors": "^8.3.0",
"@fastify/cors": "^10.0.1",
"@fastify/multipart": "^8.2.0",
"@fastify/rate-limit": "^9.0.0",
"@fastify/session": "^10.4.0",
"@fastify/swagger": "^8.10.0",
"@fastify/swagger": "^9.2.0",
"@fastify/swagger-ui": "^5.1.0",
"@prisma/client": "5.6.0",
"add": "^2.0.6",
"axios": "^1.5.0",
"bcrypt": "^5.0.1",
"dotenv": "^16.0.0",
"email-reply-parser": "^1.8.1",
"fastify": "4.22.2",
"fastify": "5.1",
"fastify-formidable": "^3.0.2",
"fastify-multer": "^2.0.3",
"formidable": "^3.5.1",
Expand Down
5 changes: 5 additions & 0 deletions apps/api/src/controllers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ export function configRoutes(fastify: FastifyInstance) {
});
});
}

reply.send({
success: true,
active: false,
});
}
);

Expand Down
28 changes: 24 additions & 4 deletions apps/api/src/controllers/data.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import { requirePermission } from "../lib/roles";
import { prisma } from "../prisma";

export function dataRoutes(fastify: FastifyInstance) {
// Get total count of all tickets
fastify.get(
"/api/v1/data/tickets/all",

{
preHandler: requirePermission(["issue::read"]),
},
async (request: FastifyRequest, reply: FastifyReply) => {
const result = await prisma.ticket.count({
where: { hidden: false },
Expand All @@ -18,7 +21,9 @@ export function dataRoutes(fastify: FastifyInstance) {
// Get total count of all completed tickets
fastify.get(
"/api/v1/data/tickets/completed",

{
preHandler: requirePermission(["issue::read"]),
},
async (request: FastifyRequest, reply: FastifyReply) => {
const result = await prisma.ticket.count({
where: { isComplete: true, hidden: false },
Expand All @@ -31,7 +36,9 @@ export function dataRoutes(fastify: FastifyInstance) {
// Get total count of all open tickets
fastify.get(
"/api/v1/data/tickets/open",

{
preHandler: requirePermission(["issue::read"]),
},
async (request: FastifyRequest, reply: FastifyReply) => {
const result = await prisma.ticket.count({
where: { isComplete: false, hidden: false },
Expand All @@ -44,7 +51,9 @@ export function dataRoutes(fastify: FastifyInstance) {
// Get total of all unsassigned tickets
fastify.get(
"/api/v1/data/tickets/unassigned",

{
preHandler: requirePermission(["issue::read"]),
},
async (request: FastifyRequest, reply: FastifyReply) => {
const result = await prisma.ticket.count({
where: { userId: null, hidden: false, isComplete: false },
Expand All @@ -53,4 +62,15 @@ export function dataRoutes(fastify: FastifyInstance) {
reply.send({ count: result });
}
);

// Get all logs
fastify.get(
"/api/v1/data/logs",
async (request: FastifyRequest, reply: FastifyReply) => {
const logs = await import("fs/promises").then((fs) =>
fs.readFile("logs.log", "utf-8")
);
reply.send({ logs: logs });
}
);
}
27 changes: 20 additions & 7 deletions apps/api/src/controllers/notebook.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import { track } from "../lib/hog";
import { requirePermission } from "../lib/roles";
import { checkSession } from "../lib/session";
import { prisma } from "../prisma";

Expand All @@ -19,7 +20,9 @@ export function notebookRoutes(fastify: FastifyInstance) {
// Create a new entry
fastify.post(
"/api/v1/notebook/note/create",

{
preHandler: requirePermission(["document::create"]),
},
async (request: FastifyRequest, reply: FastifyReply) => {
const { content, title }: any = request.body;
const user = await checkSession(request);
Expand All @@ -43,7 +46,9 @@ export function notebookRoutes(fastify: FastifyInstance) {
// Get all entries
fastify.get(
"/api/v1/notebooks/all",

{
preHandler: requirePermission(["document::read"]),
},
async (request: FastifyRequest, reply: FastifyReply) => {
const user = await checkSession(request);

Expand All @@ -58,7 +63,9 @@ export function notebookRoutes(fastify: FastifyInstance) {
// Get a single entry
fastify.get(
"/api/v1/notebooks/note/:id",

{
preHandler: requirePermission(["document::read"]),
},
async (request: FastifyRequest, reply: FastifyReply) => {
const user = await checkSession(request);

Expand All @@ -75,14 +82,17 @@ export function notebookRoutes(fastify: FastifyInstance) {
// Delete an entry
fastify.delete(
"/api/v1/notebooks/note/:id",
{
preHandler: requirePermission(["document::delete"]),
},
async (request: FastifyRequest, reply: FastifyReply) => {
const user = await checkSession(request);
const { id }: any = request.params;

await prisma.notes.delete({
where: {
where: {
id: id,
userId: user!.id
userId: user!.id,
},
});

Expand All @@ -95,15 +105,18 @@ export function notebookRoutes(fastify: FastifyInstance) {
// Update an entry
fastify.put(
"/api/v1/notebooks/note/:id/update",
{
preHandler: requirePermission(["document::update"]),
},
async (request: FastifyRequest, reply: FastifyReply) => {
const user = await checkSession(request);
const { id }: any = request.params;
const { content, title }: any = request.body;

await prisma.notes.update({
where: {
where: {
id: id,
userId: user!.id
userId: user!.id,
},
data: {
title: title,
Expand Down
Loading

0 comments on commit 44256d1

Please sign in to comment.