6cf86d5916
* Delete v2 Stripe routes * Delete v2 billing/usage pages * Delete v2 integration pages * Delete v2 project pages * Deleted a load of components and services * Deleted a load more components, presenters and services * Deleted another 100 files or so… * Removed old v2 paths * Removed named icons from form titles * Removed more string icons * Delete NamedIcon * Fixed some type errors * Delete endpointApi * Removed v2 from core/sdk * Post merge fixes * added explicit return types * using the new sdk export without v3 * Delete old v2 file * Added explicit return types because TS was complaining… * Don’t export RuntimeEnvironmentType from two core files. Was causing TS issue * Fix for removal of NamedIcon in new route * Removed strange eslintrc rule * Use the new redis client --------- Co-authored-by: James Ritchie <james@trigger.dev>
65 lines
1.4 KiB
TypeScript
65 lines
1.4 KiB
TypeScript
import { PrismaClient } from "@trigger.dev/database";
|
|
import { prisma } from "~/db.server";
|
|
import { logger } from "./logger.server";
|
|
|
|
type Options = ({ projectId: string } | { projectSlug: string }) & {
|
|
userId: string;
|
|
};
|
|
|
|
export class DeleteProjectService {
|
|
#prismaClient: PrismaClient;
|
|
|
|
constructor(prismaClient: PrismaClient = prisma) {
|
|
this.#prismaClient = prismaClient;
|
|
}
|
|
|
|
public async call(options: Options) {
|
|
const projectId = await this.#getProjectId(options);
|
|
const project = await this.#prismaClient.project.findFirst({
|
|
include: {
|
|
environments: true,
|
|
organization: true,
|
|
},
|
|
where: {
|
|
id: projectId,
|
|
organization: { members: { some: { userId: options.userId } } },
|
|
},
|
|
});
|
|
|
|
if (!project) {
|
|
throw new Error("Project not found");
|
|
}
|
|
|
|
if (project.deletedAt) {
|
|
return;
|
|
}
|
|
|
|
//mark the project as deleted
|
|
await this.#prismaClient.project.update({
|
|
where: {
|
|
id: project.id,
|
|
},
|
|
data: {
|
|
deletedAt: new Date(),
|
|
},
|
|
});
|
|
}
|
|
|
|
async #getProjectId(options: Options) {
|
|
if ("projectId" in options) {
|
|
return options.projectId;
|
|
}
|
|
|
|
const { id } = await this.#prismaClient.project.findFirstOrThrow({
|
|
select: {
|
|
id: true,
|
|
},
|
|
where: {
|
|
slug: options.projectSlug,
|
|
},
|
|
});
|
|
|
|
return id;
|
|
}
|
|
}
|