Add endpoints

This commit is contained in:
Owen Schwartz 2024-10-01 21:34:07 -04:00
parent fc5dca136f
commit 1273747099
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD
22 changed files with 350 additions and 45 deletions

View file

@ -1,43 +0,0 @@
import { Request, Response, NextFunction } from 'express';
import { DrizzleError, eq } from 'drizzle-orm';
import { sites, resources, targets, exitNodes } from '@server/db/schema';
import db from '@server/db';
import logger from '@server/logger';
interface CreateSiteRequest {
publicKey: string;
name: string;
orgId: number;
}
export const createSite = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
try {
const createSiteRequest: CreateSiteRequest = req.body;
// pick a subdomain not used
// pick a subnet not used
// pick an exit node
// const site = db
// .insert(sites)
// .values({
// orgId: createSiteRequest.orgId,
// exitNode: exitNodeId,
// name: createSiteRequest.name,
// subdomain: subdomain,
// pubKey: createSiteRequest.publicKey,
// subnet: subnet,
// })
// .returning()
// .get();
const site = {
}
res.status(200).json(site);
} catch (error) {
logger.error('Error creating site:', error);
res.status(500).json({ error: 'Internal server error' });
}
};

View file

@ -1,7 +1,26 @@
import { Router } from "express";
import { createSite } from "./createSite";
import { signup } from "@server/auth/signup";
import { login } from "@server/auth/login";
import { getSite } from "./site/getSite";
import { createSite } from "./site/createSite";
import { updateSite } from "./site/updateSite";
import { deleteSite } from "./site/deleteSite";
import { getOrg } from "./org/getOrg";
import { createOrg } from "./org/createOrg";
import { updateOrg } from "./org/updateOrg";
import { deleteOrg } from "./org/deleteOrg";
import { getResource } from "./resource/getResource";
import { createResource } from "./resource/createResource";
import { updateResource } from "./resource/updateResource";
import { deleteResource } from "./resource/deleteResource";
import { getTarget } from "./target/getTarget";
import { createTarget } from "./target/createTarget";
import { updateTarget } from "./target/updateTarget";
import { deleteTarget } from "./target/deleteTarget";
import { getUser } from "./user/getUser";
import { createUser } from "./user/createUser";
import { updateUser } from "./user/updateUser";
import { deleteUser } from "./user/deleteUser";
const global = Router();
@ -9,7 +28,26 @@ global.get("/", (_, res) => {
res.status(200).json({ message: "Healthy" });
});
global.get("/createSite", createSite);
global.get("/site", getSite);
global.put("/site", createSite);
global.post("/site", updateSite);
global.delete("/site", deleteSite);
global.get("/org", getOrg);
global.put("/org", createOrg);
global.post("/org", updateOrg);
global.delete("/org", deleteOrg);
global.get("/resource", getResource);
global.put("/resource", createResource);
global.post("/resource", updateResource);
global.delete("/resource", deleteResource);
global.get("/target", getTarget);
global.put("/target", createTarget);
global.post("/target", updateTarget);
global.delete("/target", deleteTarget);
global.get("/user", getUser);
global.put("/user", createUser);
global.post("/user", updateUser);
global.delete("/user", deleteUser);
// auth
global.post("/signup", signup);

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function createOrg(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function deleteOrg(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function getOrg(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function updateOrg(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function createResource(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function deleteResource(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function getResource(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function updateResource(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,21 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
interface CreateSiteRequest {
publicKey: string;
name: string;
orgId: number;
}
export async function createSite(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,19 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
interface DeleteSiteRequest {
siteId: string;
}
export async function deleteSite(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function getSite(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function updateSite(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function createTarget(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function deleteTarget(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function getTarget(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function updateTarget(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function createUser(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function deleteUser(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function getUser(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}

View file

@ -0,0 +1,15 @@
import { Request, Response, NextFunction } from 'express';
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
export async function updateUser(req: Request, res: Response, next: NextFunction) {
return res.status(HttpCode.OK).send(
response<null>({
data: null,
success: true,
error: false,
message: "Logged in successfully",
status: HttpCode.OK,
}),
);
}