mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-09 04:06:36 +00:00
Fixing stuff
This commit is contained in:
@@ -9,6 +9,7 @@ import fetch from 'node-fetch';
|
||||
import { ActionsEnum, checkUserActionPermission } from '@server/auth/actions';
|
||||
import logger from '@server/logger';
|
||||
import { eq, and } from 'drizzle-orm';
|
||||
import { getUniqueName } from '@server/db/names';
|
||||
|
||||
const API_BASE_URL = "http://localhost:3000";
|
||||
|
||||
@@ -24,6 +25,16 @@ const createSiteSchema = z.object({
|
||||
subnet: z.string().optional(),
|
||||
});
|
||||
|
||||
export type GetSiteResponse = {
|
||||
name: string;
|
||||
siteId: number;
|
||||
orgId: string;
|
||||
niceId: string;
|
||||
// niceId: string;
|
||||
// subdomain: string;
|
||||
// subnet: string;
|
||||
};
|
||||
|
||||
export async function createSite(req: Request, res: Response, next: NextFunction): Promise<any> {
|
||||
try {
|
||||
// Validate request body
|
||||
@@ -62,10 +73,15 @@ export async function createSite(req: Request, res: Response, next: NextFunction
|
||||
return next(createHttpError(HttpCode.FORBIDDEN, 'User does not have a role'));
|
||||
}
|
||||
|
||||
const niceId = getUniqueName();
|
||||
|
||||
// TODO: pick a subnet
|
||||
|
||||
// Create new site in the database
|
||||
const newSite = await db.insert(sites).values({
|
||||
const [newSite] = await db.insert(sites).values({
|
||||
orgId,
|
||||
name,
|
||||
niceId,
|
||||
subdomain,
|
||||
pubKey,
|
||||
subnet,
|
||||
@@ -87,19 +103,26 @@ export async function createSite(req: Request, res: Response, next: NextFunction
|
||||
|
||||
await db.insert(roleSites).values({
|
||||
roleId: superuserRole[0].roleId,
|
||||
siteId: newSite[0].siteId,
|
||||
siteId: newSite.siteId,
|
||||
});
|
||||
|
||||
if (req.userOrgRoleId != superuserRole[0].roleId) {
|
||||
// make sure the user can access the site
|
||||
db.insert(userSites).values({
|
||||
userId: req.user?.userId!,
|
||||
siteId: newSite[0].siteId,
|
||||
siteId: newSite.siteId,
|
||||
});
|
||||
}
|
||||
|
||||
return response(res, {
|
||||
data: newSite[0],
|
||||
data: {
|
||||
name: newSite.name,
|
||||
niceId: newSite.niceId,
|
||||
siteId: newSite.siteId,
|
||||
orgId: newSite.orgId,
|
||||
// subdomain: newSite.subdomain,
|
||||
// subnet: newSite.subnet,
|
||||
},
|
||||
success: true,
|
||||
error: false,
|
||||
message: "Site created successfully",
|
||||
|
||||
Reference in New Issue
Block a user