mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 07:35:09 +00:00
Slug projects and filter type
This commit is contained in:
@@ -5,6 +5,8 @@ import { ProjectsSchema, ProjectUpgradeStatus, ProjectVersion, TableName, TProje
|
||||
import { BadRequestError, DatabaseError } from "@app/lib/errors";
|
||||
import { ormify, selectAllTableCols, sqlNestRelationships } from "@app/lib/knex";
|
||||
|
||||
import { ProjectFilterType } from "./project-types";
|
||||
|
||||
export type TProjectDALFactory = ReturnType<typeof projectDALFactory>;
|
||||
|
||||
export const projectDALFactory = (db: TDbClient) => {
|
||||
@@ -139,7 +141,7 @@ export const projectDALFactory = (db: TDbClient) => {
|
||||
{ column: `${TableName.Project}.name`, order: "asc" },
|
||||
{ column: `${TableName.Environment}.position`, order: "asc" }
|
||||
]);
|
||||
return sqlNestRelationships({
|
||||
const project = sqlNestRelationships({
|
||||
data: workspaces,
|
||||
key: "id",
|
||||
parentMapper: ({ _id, ...el }) => ({ _id, ...ProjectsSchema.parse(el) }),
|
||||
@@ -155,6 +157,12 @@ export const projectDALFactory = (db: TDbClient) => {
|
||||
}
|
||||
]
|
||||
})?.[0];
|
||||
|
||||
if (!project) {
|
||||
throw new BadRequestError({ message: "Project not found" });
|
||||
}
|
||||
|
||||
return project;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Find all projects" });
|
||||
}
|
||||
@@ -177,7 +185,7 @@ export const projectDALFactory = (db: TDbClient) => {
|
||||
{ column: `${TableName.Project}.name`, order: "asc" },
|
||||
{ column: `${TableName.Environment}.position`, order: "asc" }
|
||||
]);
|
||||
return sqlNestRelationships({
|
||||
const project = sqlNestRelationships({
|
||||
data: projects,
|
||||
key: "id",
|
||||
parentMapper: ({ _id, ...el }) => ({ _id, ...ProjectsSchema.parse(el) }),
|
||||
@@ -193,11 +201,31 @@ export const projectDALFactory = (db: TDbClient) => {
|
||||
}
|
||||
]
|
||||
})?.[0];
|
||||
|
||||
if (!project) {
|
||||
throw new BadRequestError({ message: "Project not found" });
|
||||
}
|
||||
|
||||
return project;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Find project by slug" });
|
||||
}
|
||||
};
|
||||
|
||||
const findProjectByFilter = async (filter: string, type: ProjectFilterType) => {
|
||||
try {
|
||||
if (type === ProjectFilterType.ID) {
|
||||
return await findProjectById(filter);
|
||||
}
|
||||
if (type === ProjectFilterType.SLUG) {
|
||||
return await findProjectBySlug(filter);
|
||||
}
|
||||
throw new BadRequestError({ message: "Invalid filter type" });
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: `Failed to find project by ${type}` });
|
||||
}
|
||||
};
|
||||
|
||||
const checkProjectUpgradeStatus = async (projectId: string) => {
|
||||
const project = await projectOrm.findById(projectId);
|
||||
const upgradeInProgress =
|
||||
@@ -217,6 +245,7 @@ export const projectDALFactory = (db: TDbClient) => {
|
||||
findAllProjectsByIdentity,
|
||||
findProjectGhostUser,
|
||||
findProjectById,
|
||||
findProjectByFilter,
|
||||
findProjectBySlug,
|
||||
checkProjectUpgradeStatus
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user