feat: fixed migration issues and resolved all routes in frontend

This commit is contained in:
=
2024-12-13 21:38:42 +05:30
parent 69bf9dc20f
commit a857375cc1
69 changed files with 547 additions and 265 deletions
@@ -1,11 +1,12 @@
import slugify from "@sindresorhus/slugify";
import { Knex } from "knex";
import { v4 as uuidV4 } from "uuid";
import slugify from "@sindresorhus/slugify";
import { ProjectType, TableName } from "../schemas";
import { alphaNumericNanoId } from "@app/lib/nanoid";
/* eslint-disable no-await-in-loop,no-param-reassign,@typescript-eslint/ban-ts-comment */
import { ProjectType, TableName } from "../schemas";
/* eslint-disable no-await-in-loop,@typescript-eslint/ban-ts-comment */
const newProject = async (knex: Knex, projectId: string, projectType: ProjectType) => {
const newProjectId = uuidV4();
const project = await knex(TableName.Project).where("id", projectId).first();
@@ -24,10 +25,12 @@ const newProject = async (knex: Knex, projectId: string, projectType: ProjectTyp
projectCustomRoles.map((el) => {
const id = uuidV4();
customRoleMapping[el.id] = id;
el.id = id;
el.projectId = newProjectId;
el.permissions = el.permissions ? JSON.stringify(el.permissions) : el.permissions;
return el;
return {
...el,
id,
projectId: newProjectId,
permissions: el.permissions ? JSON.stringify(el.permissions) : el.permissions
};
})
);
}
@@ -38,9 +41,7 @@ const newProject = async (knex: Knex, projectId: string, projectType: ProjectTyp
groupMemberships.map((el) => {
const id = uuidV4();
groupMembershipMapping[el.id] = id;
el.id = id;
el.projectId = newProjectId;
return el;
return { ...el, id, projectId: newProjectId };
})
);
}
@@ -53,10 +54,9 @@ const newProject = async (knex: Knex, projectId: string, projectType: ProjectTyp
await knex(TableName.GroupProjectMembershipRole).insert(
groupMembershipRoles.map((el) => {
const id = uuidV4();
el.id = id;
el.projectMembershipId = groupMembershipMapping[el.id];
el.customRoleId = el.customRoleId ? customRoleMapping[el.customRoleId] : el.customRoleId;
return el;
const projectMembershipId = groupMembershipMapping[el.id];
const customRoleId = el.customRoleId ? customRoleMapping[el.customRoleId] : el.customRoleId;
return { ...el, id, projectMembershipId, customRoleId };
})
);
}
@@ -68,9 +68,7 @@ const newProject = async (knex: Knex, projectId: string, projectType: ProjectTyp
identities.map((el) => {
const id = uuidV4();
identityProjectMembershipMapping[el.id] = id;
el.id = id;
el.projectId = newProjectId;
return el;
return { ...el, id, projectId: newProjectId };
})
);
}
@@ -83,10 +81,9 @@ const newProject = async (knex: Knex, projectId: string, projectType: ProjectTyp
await knex(TableName.IdentityProjectMembershipRole).insert(
identitiesRoles.map((el) => {
const id = uuidV4();
el.id = id;
el.projectMembershipId = identityProjectMembershipMapping[el.projectMembershipId];
el.customRoleId = el.customRoleId ? customRoleMapping[el.customRoleId] : el.customRoleId;
return el;
const projectMembershipId = identityProjectMembershipMapping[el.projectMembershipId];
const customRoleId = el.customRoleId ? customRoleMapping[el.customRoleId] : el.customRoleId;
return { ...el, id, projectMembershipId, customRoleId };
})
);
}
@@ -98,9 +95,7 @@ const newProject = async (knex: Knex, projectId: string, projectType: ProjectTyp
projectUserMembers.map((el) => {
const id = uuidV4();
projectMembershipMapping[el.id] = id;
el.id = id;
el.projectId = newProjectId;
return el;
return { ...el, id, projectId: newProjectId };
})
);
}
@@ -112,10 +107,9 @@ const newProject = async (knex: Knex, projectId: string, projectType: ProjectTyp
await knex(TableName.ProjectUserMembershipRole).insert(
membershipRoles.map((el) => {
const id = uuidV4();
el.id = id;
el.projectMembershipId = projectMembershipMapping[el.projectMembershipId];
el.customRoleId = el.customRoleId ? customRoleMapping[el.customRoleId] : el.customRoleId;
return el;
const projectMembershipId = projectMembershipMapping[el.projectMembershipId];
const customRoleId = el.customRoleId ? customRoleMapping[el.customRoleId] : el.customRoleId;
return { ...el, id, projectMembershipId, customRoleId };
})
);
}
@@ -125,10 +119,8 @@ const newProject = async (knex: Knex, projectId: string, projectType: ProjectTyp
await knex(TableName.KmsKey).insert(
kmsKeys.map((el) => {
const id = uuidV4();
el.id = id;
el.projectId = newProjectId;
el.slug = slugify(alphaNumericNanoId(8).toLowerCase());
return el;
const slug = slugify(alphaNumericNanoId(8).toLowerCase());
return { ...el, id, slug, projectId: newProjectId };
})
);
}
@@ -143,9 +135,7 @@ const newProject = async (knex: Knex, projectId: string, projectType: ProjectTyp
await knex(TableName.ProjectKeys).insert(
projectKeys.map((el) => {
const id = uuidV4();
el.id = id;
el.projectId = newProjectId;
return el;
return { ...el, id, projectId: newProjectId };
})
);
}
@@ -154,16 +144,14 @@ const newProject = async (knex: Knex, projectId: string, projectType: ProjectTyp
if (serviceTokens.length) {
await knex(TableName.ServiceToken).insert(
serviceTokens.map((el) => {
el.id = uuidV4();
el.projectId = projectId;
el.scopes = el.scopes ? JSON.stringify(el.scopes) : el.scopes;
return el;
const id = uuidV4();
const scopes = el.scopes ? JSON.stringify(el.scopes) : el.scopes;
return { ...el, id, scopes, projectId: newProjectId };
})
);
}
return newProjectId;
};
/* eslint-enable */
const BATCH_SIZE = 500;
export async function up(knex: Knex): Promise<void> {
@@ -137,7 +137,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
.enum(["true", "false"])
.default("false")
.transform((value) => value === "true"),
type: z.nativeEnum(ProjectType).optional()
type: z.enum([ProjectType.SecretManager, ProjectType.Cmek, ProjectType.CertificateManager, "all"]).optional()
}),
response: {
200: z.object({
+1 -1
View File
@@ -197,7 +197,7 @@ export const orgServiceFactory = ({
const findAllWorkspaces = async ({ actor, actorId, orgId, type }: TFindAllWorkspacesDTO) => {
if (actor === ActorType.USER) {
const workspaces = await projectDAL.findAllProjects(actorId, orgId, type);
const workspaces = await projectDAL.findAllProjects(actorId, orgId, type || "all");
return workspaces;
}
+7 -3
View File
@@ -19,7 +19,7 @@ export type TProjectDALFactory = ReturnType<typeof projectDALFactory>;
export const projectDALFactory = (db: TDbClient) => {
const projectOrm = ormify(db, TableName.Project);
const findAllProjects = async (userId: string, orgId: string, projectType?: ProjectType | null) => {
const findAllProjects = async (userId: string, orgId: string, projectType: ProjectType | "all") => {
try {
const workspaces = await db
.replicaNode()(TableName.ProjectMembership)
@@ -27,7 +27,7 @@ export const projectDALFactory = (db: TDbClient) => {
.join(TableName.Project, `${TableName.ProjectMembership}.projectId`, `${TableName.Project}.id`)
.where(`${TableName.Project}.orgId`, orgId)
.andWhere((qb) => {
if (projectType) {
if (projectType !== "all") {
void qb.where(`${TableName.Project}.type`, projectType);
}
})
@@ -130,7 +130,11 @@ export const projectDALFactory = (db: TDbClient) => {
.replicaNode()(TableName.IdentityProjectMembership)
.where({ identityId })
.join(TableName.Project, `${TableName.IdentityProjectMembership}.projectId`, `${TableName.Project}.id`)
.where(`${TableName.Project}.type`, projectType)
.andWhere((qb) => {
if (projectType) {
void qb.where(`${TableName.Project}.type`, projectType);
}
})
.leftJoin(TableName.Environment, `${TableName.Environment}.projectId`, `${TableName.Project}.id`)
.select(
selectAllTableCols(TableName.Project),
@@ -431,7 +431,13 @@ export const projectServiceFactory = ({
return deletedProject;
};
const getProjects = async ({ actorId, includeRoles, actorAuthMethod, actorOrgId, type }: TListProjectsDTO) => {
const getProjects = async ({
actorId,
includeRoles,
actorAuthMethod,
actorOrgId,
type = ProjectType.SecretManager
}: TListProjectsDTO) => {
const workspaces = await projectDAL.findAllProjects(actorId, actorOrgId, type);
if (includeRoles) {
@@ -85,7 +85,7 @@ export type TDeleteProjectDTO = {
export type TListProjectsDTO = {
includeRoles: boolean;
type?: ProjectType | null;
type?: ProjectType | "all";
} & Omit<TProjectPermission, "projectId">;
export type TUpgradeProjectDTO = {