mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 13:26:31 +00:00
Find projects by identity
This commit is contained in:
@@ -30,7 +30,7 @@ export const projectDALFactory = (db: TDbClient) => {
|
|||||||
db.ref("name").withSchema(TableName.Environment).as("envName")
|
db.ref("name").withSchema(TableName.Environment).as("envName")
|
||||||
)
|
)
|
||||||
.orderBy("createdAt", "asc", "last");
|
.orderBy("createdAt", "asc", "last");
|
||||||
return sqlNestRelationships({
|
const nestedWorkspaces = sqlNestRelationships({
|
||||||
data: workspaces,
|
data: workspaces,
|
||||||
key: "id",
|
key: "id",
|
||||||
parentMapper: ({ _id, ...el }) => ({ _id, ...ProjectsSchema.parse(el) }),
|
parentMapper: ({ _id, ...el }) => ({ _id, ...ProjectsSchema.parse(el) }),
|
||||||
@@ -46,11 +46,67 @@ export const projectDALFactory = (db: TDbClient) => {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return nestedWorkspaces.map((workspace) => ({
|
||||||
|
...workspace,
|
||||||
|
organization: workspace.id
|
||||||
|
}));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ error, name: "Find all projects" });
|
throw new DatabaseError({ error, name: "Find all projects" });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const findAllProjectsByIdentity = async (identityId: string) => {
|
||||||
|
try {
|
||||||
|
const workspaces = await db(TableName.IdentityProjectMembership)
|
||||||
|
.where({ identityId })
|
||||||
|
.join(
|
||||||
|
TableName.Project,
|
||||||
|
`${TableName.IdentityProjectMembership}.projectId`,
|
||||||
|
`${TableName.Project}.id`
|
||||||
|
)
|
||||||
|
.leftJoin(
|
||||||
|
TableName.Environment,
|
||||||
|
`${TableName.Environment}.projectId`,
|
||||||
|
`${TableName.Project}.id`
|
||||||
|
)
|
||||||
|
.select(
|
||||||
|
selectAllTableCols(TableName.Project),
|
||||||
|
db.ref("id").withSchema(TableName.Project).as("_id"),
|
||||||
|
db.ref("id").withSchema(TableName.Environment).as("envId"),
|
||||||
|
db.ref("slug").withSchema(TableName.Environment).as("envSlug"),
|
||||||
|
db.ref("name").withSchema(TableName.Environment).as("envName")
|
||||||
|
)
|
||||||
|
.orderBy("createdAt", "asc", "last");
|
||||||
|
|
||||||
|
const nestedWorkspaces = sqlNestRelationships({
|
||||||
|
data: workspaces,
|
||||||
|
key: "id",
|
||||||
|
parentMapper: ({ _id, ...el }) => ({ _id, ...ProjectsSchema.parse(el) }),
|
||||||
|
childrenMapper: [
|
||||||
|
{
|
||||||
|
key: "envId",
|
||||||
|
label: "environments" as const,
|
||||||
|
mapper: ({ envId: id, envSlug: slug, envName: name }) => ({
|
||||||
|
id,
|
||||||
|
slug,
|
||||||
|
name
|
||||||
|
})
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
// we need to add "organization" to each workspace entry
|
||||||
|
|
||||||
|
return nestedWorkspaces.map((workspace) => ({
|
||||||
|
...workspace,
|
||||||
|
organization: workspace.id
|
||||||
|
}));
|
||||||
|
} catch (error) {
|
||||||
|
throw new DatabaseError({ error, name: "Find all projects by identity" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const findProjectById = async (id: string) => {
|
const findProjectById = async (id: string) => {
|
||||||
try {
|
try {
|
||||||
const workspaces = await db(TableName.ProjectMembership)
|
const workspaces = await db(TableName.ProjectMembership)
|
||||||
@@ -96,6 +152,7 @@ export const projectDALFactory = (db: TDbClient) => {
|
|||||||
return {
|
return {
|
||||||
...projectOrm,
|
...projectOrm,
|
||||||
findAllProjects,
|
findAllProjects,
|
||||||
|
findAllProjectsByIdentity,
|
||||||
findProjectById
|
findProjectById
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user