mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-27 07:16:40 +00:00
Fix resource new id number
This commit is contained in:
@@ -11,7 +11,7 @@ import { eq, and } from 'drizzle-orm';
|
||||
import stoi from '@server/utils/stoi';
|
||||
|
||||
const createResourceParamsSchema = z.object({
|
||||
siteId: z.string().optional().transform(stoi).pipe(z.number().int().positive().optional()),
|
||||
siteId: z.string().optional().transform(stoi).pipe(z.number().int().positive().optional()),
|
||||
orgId: z.string()
|
||||
});
|
||||
|
||||
@@ -64,7 +64,7 @@ export async function createResource(req: Request, res: Response, next: NextFunc
|
||||
.from(orgs)
|
||||
.where(eq(orgs.orgId, orgId))
|
||||
.limit(1);
|
||||
|
||||
|
||||
if (org.length === 0) {
|
||||
return next(
|
||||
createHttpError(
|
||||
@@ -75,11 +75,11 @@ export async function createResource(req: Request, res: Response, next: NextFunc
|
||||
}
|
||||
|
||||
// Generate a unique resourceId
|
||||
const resourceId = `${subdomain}.${org[0].orgId}.${org[0].domain}`;
|
||||
const fullDomain = `${subdomain}.${org[0].orgId}.${org[0].domain}`;
|
||||
|
||||
// Create new resource in the database
|
||||
const newResource = await db.insert(resources).values({
|
||||
resourceId,
|
||||
fullDomain,
|
||||
siteId,
|
||||
orgId,
|
||||
name,
|
||||
|
||||
@@ -11,7 +11,7 @@ import logger from '@server/logger';
|
||||
|
||||
// Define Zod schema for request parameters validation
|
||||
const deleteResourceSchema = z.object({
|
||||
resourceId: z.string()
|
||||
resourceId: z.string().transform(Number).pipe(z.number().int().positive()),
|
||||
});
|
||||
|
||||
export async function deleteResource(req: Request, res: Response, next: NextFunction): Promise<any> {
|
||||
|
||||
@@ -11,11 +11,11 @@ import logger from '@server/logger';
|
||||
|
||||
// Define Zod schema for request parameters validation
|
||||
const getResourceSchema = z.object({
|
||||
resourceId: z.string()
|
||||
resourceId: z.string().transform(Number).pipe(z.number().int().positive()),
|
||||
});
|
||||
|
||||
export type GetResourceResponse = {
|
||||
resourceId: string;
|
||||
resourceId: number;
|
||||
siteId: number;
|
||||
orgId: string;
|
||||
name: string;
|
||||
|
||||
@@ -10,7 +10,7 @@ import { ActionsEnum, checkUserActionPermission } from '@server/auth/actions';
|
||||
import logger from '@server/logger';
|
||||
|
||||
const listResourceRolesSchema = z.object({
|
||||
resourceId: z.string(),
|
||||
resourceId: z.string().transform(Number).pipe(z.number().int().positive()),
|
||||
});
|
||||
|
||||
export async function listResourceRoles(req: Request, res: Response, next: NextFunction): Promise<any> {
|
||||
|
||||
@@ -41,7 +41,7 @@ const listResourcesSchema = z.object({
|
||||
});
|
||||
|
||||
function queryResources(
|
||||
accessibleResourceIds: string[],
|
||||
accessibleResourceIds: number[],
|
||||
siteId?: number,
|
||||
orgId?: string,
|
||||
) {
|
||||
@@ -141,7 +141,7 @@ export async function listResources(
|
||||
// Get the list of resources the user has access to
|
||||
const accessibleResources = await db
|
||||
.select({
|
||||
resourceId: sql<string>`COALESCE(${userResources.resourceId}, ${roleResources.resourceId})`,
|
||||
resourceId: sql<number>`COALESCE(${userResources.resourceId}, ${roleResources.resourceId})`,
|
||||
})
|
||||
.from(userResources)
|
||||
.fullJoin(
|
||||
|
||||
@@ -11,7 +11,7 @@ import logger from '@server/logger';
|
||||
|
||||
// Define Zod schema for request parameters validation
|
||||
const updateResourceParamsSchema = z.object({
|
||||
resourceId: z.string()
|
||||
resourceId: z.string().transform(Number).pipe(z.number().int().positive()),
|
||||
});
|
||||
|
||||
// Define Zod schema for request body validation
|
||||
|
||||
Reference in New Issue
Block a user