Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: enable disable ecosystem: 107 #115

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/user/src/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ export class UserService {

async getProfile(payload: { id }): Promise<object> {
try {
return this.userRepository.getUserById(payload.id);
const userData = await this.userRepository.getUserById(payload.id);
const platformConfigData = await this.prisma.platform_config.findMany();
userData['enableEcosystem'] = platformConfigData[0].enableEcosystem;
return userData;
} catch (error) {
this.logger.error(`get user: ${JSON.stringify(error)}`);
throw new RpcException(error.response ? error.response : error);
Expand Down
15 changes: 15 additions & 0 deletions libs/prisma-service/prisma/data/credebl-master-table.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@
"description": "Joins the organization as member"
}
],
"ecosystemRoleData": [
{
"name": "Ecosystem Owner",
"description": "Ecosystem Owner"
},
{
"name": "Ecosystem Lead",
"description": "Ecosystem Lead"
},
{
"name": "Ecosystem Member",
"description": "Ecosystem Member"
}
],

"agentTypeData": [
{
"agent": "AFJ"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Warnings:

- The primary key for the `ecosystem_roles` table will be changed. If it partially fails, the table could be left without primary key constraint.

*/
-- DropForeignKey
ALTER TABLE "ecosystem_orgs" DROP CONSTRAINT "ecosystem_orgs_ecosystemRoleId_fkey";

-- AlterTable
ALTER TABLE "ecosystem_orgs" ALTER COLUMN "ecosystemRoleId" SET DATA TYPE TEXT;

-- AlterTable
ALTER TABLE "ecosystem_roles" DROP CONSTRAINT "ecosystem_roles_pkey",
ALTER COLUMN "id" DROP DEFAULT,
ALTER COLUMN "id" SET DATA TYPE TEXT,
ADD CONSTRAINT "ecosystem_roles_pkey" PRIMARY KEY ("id");
DROP SEQUENCE "ecosystem_roles_id_seq";

-- AlterTable
ALTER TABLE "platform_config" ADD COLUMN "enableEcosystem" BOOLEAN NOT NULL DEFAULT false;

-- AddForeignKey
ALTER TABLE "ecosystem_orgs" ADD CONSTRAINT "ecosystem_orgs_ecosystemRoleId_fkey" FOREIGN KEY ("ecosystemRoleId") REFERENCES "ecosystem_roles"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "ecosystem" ADD COLUMN "logoUrl" TEXT;
8 changes: 5 additions & 3 deletions libs/prisma-service/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ model platform_config {
emailFrom String @db.VarChar
apiEndpoint String @db.VarChar
tailsFileServer String @db.VarChar
enableEcosystem Boolean @default(false)
createDateTime DateTime @default(now()) @db.Timestamptz(6)
createdBy Int @default(1)
lastChangedDateTime DateTime @default(now()) @db.Timestamptz(6)
Expand Down Expand Up @@ -309,7 +310,7 @@ model presentations {
}

model ecosystem_roles {
id Int @id @default(autoincrement())
id String @id @default(uuid())
name String @unique
description String
ecosystemOrgs ecosystem_orgs[]
Expand All @@ -324,6 +325,7 @@ model ecosystem {
id String @id @default(uuid())
name String
description String
logoUrl String?
tags String
ecosystemOrgs ecosystem_orgs[]
ecosystemUsers ecosystem_users[]
Expand Down Expand Up @@ -363,11 +365,11 @@ model ecosystem_users {
}

model ecosystem_orgs {
id String @id @default(uuid()) // auto-increment
id String @id @default(uuid())
orgId String
status String
ecosystemId String
ecosystemRoleId Int
ecosystemRoleId String
ecosystem ecosystem @relation(fields: [ecosystemId], references: [id])
ecosystemRole ecosystem_roles @relation(fields: [ecosystemRoleId], references: [id])
createDateTime DateTime @default(now()) @db.Timestamptz(6)
Expand Down
14 changes: 14 additions & 0 deletions libs/prisma-service/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ const createLedger = async (): Promise<void> => {
}
};

const createEcosystemRoles = async (): Promise<void> => {
try {
const { ecosystemRoleData } = JSON.parse(configData);
const ecosystemRoles = await prisma.ecosystem_roles.createMany({
data: ecosystemRoleData
});

logger.log(ecosystemRoles);
} catch (e) {
logger.error('An error occurred seeding ecosystemRoles:', e);
}
};

async function main(): Promise<void> {

await createPlatformConfig();
Expand All @@ -123,6 +136,7 @@ async function main(): Promise<void> {
await createPlatformUserOrgRoles();
await createOrgAgentTypes();
await createLedger();
await createEcosystemRoles();
}


Expand Down