feature: Adds removing API.
This commit is contained in:
parent
68b5a9ff77
commit
2ae917acd9
13 changed files with 165 additions and 8 deletions
|
@ -8,8 +8,10 @@ import { ServerOptions, SessionToken } from "./libs/types.js";
|
|||
import { route as getPermissions } from "./routes/getPermissions.js";
|
||||
|
||||
import { route as backendCreate } from "./routes/backends/create.js";
|
||||
import { route as backendRemove } from "./routes/backends/remove.js";
|
||||
|
||||
import { route as forwardCreate } from "./routes/forward/create.js";
|
||||
import { route as forwardRemove } from "./routes/forward/remove.js";
|
||||
|
||||
import { route as userCreate } from "./routes/user/create.js";
|
||||
import { route as userRemove } from "./routes/user/remove.js";
|
||||
|
@ -43,8 +45,10 @@ const fastify = Fastify({
|
|||
getPermissions(fastify, prisma, sessionTokens, serverOptions);
|
||||
|
||||
backendCreate(fastify, prisma, sessionTokens, serverOptions);
|
||||
backendRemove(fastify, prisma, sessionTokens, serverOptions);
|
||||
|
||||
forwardCreate(fastify, prisma, sessionTokens, serverOptions);
|
||||
forwardRemove(fastify, prisma, sessionTokens, serverOptions);
|
||||
|
||||
userCreate(fastify, prisma, sessionTokens, serverOptions);
|
||||
userRemove(fastify, prisma, sessionTokens, serverOptions);
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
- [x] /api/v1/users/login
|
||||
- [x] /api/v1/users/remove
|
||||
- [ ] /api/v1/users/modify
|
||||
- [ ] /api/v1/users/search
|
||||
- [x] /api/v1/users/search
|
||||
- [x] /api/v1/backends/create
|
||||
- [ ] /api/v1/backends/remove
|
||||
- [x] /api/v1/backends/remove
|
||||
- [ ] /api/v1/backends/modify
|
||||
- [ ] /api/v1/backends/search
|
||||
- [x] /api/v1/routes/create
|
||||
- [ ] /api/v1/routes/remove
|
||||
- [x] /api/v1/routes/remove
|
||||
- [ ] /api/v1/routes/modify
|
||||
- [ ] /api/v1/routes/search
|
||||
- [x] /api/v1/getPermissions
|
52
src/routes/backends/remove.ts
Normal file
52
src/routes/backends/remove.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import type { PrismaClient } from "@prisma/client";
|
||||
import type { FastifyInstance } from "fastify";
|
||||
|
||||
import { ServerOptions, SessionToken } from "../../libs/types.js";
|
||||
import { hasPermissionByToken } from "../../libs/permissions.js";
|
||||
|
||||
export function route(fastify: FastifyInstance, prisma: PrismaClient, tokens: Record<number, SessionToken[]>, options: ServerOptions) {
|
||||
function hasPermission(token: string, permissionList: string[]): Promise<boolean> {
|
||||
return hasPermissionByToken(permissionList, token, tokens, prisma);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new route to use
|
||||
*/
|
||||
fastify.post("/api/v1/backends/remove", {
|
||||
schema: {
|
||||
body: {
|
||||
type: "object",
|
||||
required: ["token", "id"],
|
||||
|
||||
properties: {
|
||||
token: { type: "string" },
|
||||
id: { type: "number" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}, async(req, res) => {
|
||||
// @ts-ignore
|
||||
const body: {
|
||||
token: string,
|
||||
id: number
|
||||
} = req.body;
|
||||
|
||||
if (!await hasPermission(body.token, [
|
||||
"backends.remove"
|
||||
])) {
|
||||
return res.status(403).send({
|
||||
error: "Unauthorized"
|
||||
});
|
||||
};
|
||||
|
||||
await prisma.desinationProvider.delete({
|
||||
where: {
|
||||
id: body.id
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
});
|
||||
}
|
52
src/routes/forward/remove.ts
Normal file
52
src/routes/forward/remove.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import type { PrismaClient } from "@prisma/client";
|
||||
import type { FastifyInstance } from "fastify";
|
||||
|
||||
import { ServerOptions, SessionToken } from "../../libs/types.js";
|
||||
import { hasPermissionByToken } from "../../libs/permissions.js";
|
||||
|
||||
export function route(fastify: FastifyInstance, prisma: PrismaClient, tokens: Record<number, SessionToken[]>, options: ServerOptions) {
|
||||
function hasPermission(token: string, permissionList: string[]): Promise<boolean> {
|
||||
return hasPermissionByToken(permissionList, token, tokens, prisma);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new route to use
|
||||
*/
|
||||
fastify.post("/api/v1/forward/remove", {
|
||||
schema: {
|
||||
body: {
|
||||
type: "object",
|
||||
required: ["token", "id"],
|
||||
|
||||
properties: {
|
||||
token: { type: "string" },
|
||||
id: { type: "number" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}, async(req, res) => {
|
||||
// @ts-ignore
|
||||
const body: {
|
||||
token: string,
|
||||
id: number
|
||||
} = req.body;
|
||||
|
||||
if (!await hasPermission(body.token, [
|
||||
"routes.remove"
|
||||
])) {
|
||||
return res.status(403).send({
|
||||
error: "Unauthorized"
|
||||
});
|
||||
};
|
||||
|
||||
await prisma.forwardRule.delete({
|
||||
where: {
|
||||
id: body.id
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue