mirror of
https://github.com/LukeHagar/dokploy.git
synced 2025-12-06 12:27:49 +00:00
refactor: update
This commit is contained in:
@@ -25,7 +25,7 @@ export const certificateRouter = createTRPCRouter({
|
|||||||
message: "Please set a server to create a certificate",
|
message: "Please set a server to create a certificate",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return await createCertificate(input, ctx.user.ownerId);
|
return await createCertificate(input, ctx.session.activeOrganizationId);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
one: adminProcedure
|
one: adminProcedure
|
||||||
|
|||||||
@@ -4,25 +4,26 @@ import {
|
|||||||
apiRemoveRegistry,
|
apiRemoveRegistry,
|
||||||
apiTestRegistry,
|
apiTestRegistry,
|
||||||
apiUpdateRegistry,
|
apiUpdateRegistry,
|
||||||
|
registry,
|
||||||
} from "@/server/db/schema";
|
} from "@/server/db/schema";
|
||||||
import {
|
import {
|
||||||
IS_CLOUD,
|
IS_CLOUD,
|
||||||
createRegistry,
|
createRegistry,
|
||||||
execAsync,
|
execAsync,
|
||||||
execAsyncRemote,
|
execAsyncRemote,
|
||||||
findAllRegistryByUserId,
|
|
||||||
findRegistryById,
|
findRegistryById,
|
||||||
removeRegistry,
|
removeRegistry,
|
||||||
updateRegistry,
|
updateRegistry,
|
||||||
} from "@dokploy/server";
|
} from "@dokploy/server";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { adminProcedure, createTRPCRouter, protectedProcedure } from "../trpc";
|
import { adminProcedure, createTRPCRouter, protectedProcedure } from "../trpc";
|
||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
|
||||||
export const registryRouter = createTRPCRouter({
|
export const registryRouter = createTRPCRouter({
|
||||||
create: adminProcedure
|
create: adminProcedure
|
||||||
.input(apiCreateRegistry)
|
.input(apiCreateRegistry)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
return await createRegistry(input, ctx.user.ownerId);
|
return await createRegistry(input, ctx.session.activeOrganizationId);
|
||||||
}),
|
}),
|
||||||
remove: adminProcedure
|
remove: adminProcedure
|
||||||
.input(apiRemoveRegistry)
|
.input(apiRemoveRegistry)
|
||||||
@@ -61,7 +62,10 @@ export const registryRouter = createTRPCRouter({
|
|||||||
return true;
|
return true;
|
||||||
}),
|
}),
|
||||||
all: protectedProcedure.query(async ({ ctx }) => {
|
all: protectedProcedure.query(async ({ ctx }) => {
|
||||||
return await findAllRegistryByUserId(ctx.user.ownerId);
|
const registryResponse = await db.query.registry.findMany({
|
||||||
|
where: eq(registry.organizationId, ctx.session.activeOrganizationId),
|
||||||
|
});
|
||||||
|
return registryResponse;
|
||||||
}),
|
}),
|
||||||
one: adminProcedure
|
one: adminProcedure
|
||||||
.input(apiFindOneRegistry)
|
.input(apiFindOneRegistry)
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ export const findCertificateById = async (certificateId: string) => {
|
|||||||
|
|
||||||
export const createCertificate = async (
|
export const createCertificate = async (
|
||||||
certificateData: z.infer<typeof apiCreateCertificate>,
|
certificateData: z.infer<typeof apiCreateCertificate>,
|
||||||
userId: string,
|
organizationId: string,
|
||||||
) => {
|
) => {
|
||||||
const certificate = await db
|
const certificate = await db
|
||||||
.insert(certificates)
|
.insert(certificates)
|
||||||
.values({
|
.values({
|
||||||
...certificateData,
|
...certificateData,
|
||||||
userId: userId,
|
organizationId: organizationId,
|
||||||
})
|
})
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ export type Registry = typeof registry.$inferSelect;
|
|||||||
|
|
||||||
export const createRegistry = async (
|
export const createRegistry = async (
|
||||||
input: typeof apiCreateRegistry._type,
|
input: typeof apiCreateRegistry._type,
|
||||||
userId: string,
|
organizationId: string,
|
||||||
) => {
|
) => {
|
||||||
return await db.transaction(async (tx) => {
|
return await db.transaction(async (tx) => {
|
||||||
const newRegistry = await tx
|
const newRegistry = await tx
|
||||||
.insert(registry)
|
.insert(registry)
|
||||||
.values({
|
.values({
|
||||||
...input,
|
...input,
|
||||||
userId: userId,
|
organizationId: organizationId,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -135,9 +135,11 @@ export const findRegistryById = async (registryId: string) => {
|
|||||||
return registryResponse;
|
return registryResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const findAllRegistryByUserId = async (userId: string) => {
|
export const findAllRegistryByOrganizationId = async (
|
||||||
|
organizationId: string,
|
||||||
|
) => {
|
||||||
const registryResponse = await db.query.registry.findMany({
|
const registryResponse = await db.query.registry.findMany({
|
||||||
where: eq(registry.userId, userId),
|
where: eq(registry.organizationId, organizationId),
|
||||||
});
|
});
|
||||||
return registryResponse;
|
return registryResponse;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user