Skip to content

Commit

Permalink
Merge pull request #210 from desci-labs/community-update
Browse files Browse the repository at this point in the history
Community update
  • Loading branch information
hubsmoke authored Feb 19, 2024
2 parents d38914b + 1d9468b commit 42428f3
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 180 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,6 @@ REPO_SERVICE_SECRET_KEY=secretrepo
TOGGLE_CERAMIC=
# If above is set, clone `@desci-labs/desci-codex` and put the path to it here
CODEX_REPO_PATH=

# SET TO 1 to run communities seed script
RUN=1
2 changes: 1 addition & 1 deletion desci-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ modify `desci-server/package.json`

# RUNNING MIGRATIONS: when making changes to schema.prisma, run the following to migrate

DATABASE_URL=postgresql://walter:white@host.docker.internal:5433/boilerplate npx prisma migrate dev
DATABASE_URL=postgresql://walter:white@localhost:5433/boilerplate npx prisma migrate dev

# THEN

Expand Down
5 changes: 3 additions & 2 deletions desci-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
"script:increase-base-drive-storage": "debug=* node --no-warnings --enable-source-maps --loader ts-node/esm ./src/scripts/increase-base-drive-storage.ts",
"script:testing": "debug=* node --no-warnings --enable-source-maps --loader ts-node/esm ./src/scripts/testing.ts",
"script:migrate-draft-trees": "debug=* node --no-warnings --enable-source-maps --loader ts-node/esm ./src/scripts/migrate-draft-trees.ts",
"script:endorse-dpid": "debug=* node --no-warnings --enable-source-maps --loader ts-node/esm ./src/scripts/endorseDpid.ts",
"script:seed-social-data": "debug=* node --no-warnings --enable-source-maps --loader ts-node/esm ./src/scripts/seedSocialData.ts",
"script:endorse-dpid": "debug=* node --no-warnings --enable-source-maps --loader ts-node/esm ./src/scripts/endorse-dpid.ts",
"script:seed-social-data": "debug=* node --no-warnings --enable-source-maps --loader ts-node/esm ./src/scripts/seed-social-data.ts",
"script:DESTRUCTIVE-clear-social-data": "debug=* node --no-warnings --enable-source-maps --loader ts-node/esm ./src/scripts/DESTRUCTIVE-clear-social-data.ts",
"build": "rimraf dist && tsc && yarn copy-files",
"copy-files": "copyfiles -u 1 src/**/*.cjs dist/",
"generate": "npx prisma generate",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "DesciCommunity" ADD COLUMN "hidden" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "links" TEXT[],
ADD COLUMN "memberString" TEXT[],
ADD COLUMN "subtitle" TEXT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "AttestationTemplate" ADD COLUMN "desciCommunityId" INTEGER;

-- AddForeignKey
ALTER TABLE "AttestationTemplate" ADD CONSTRAINT "AttestationTemplate_desciCommunityId_fkey" FOREIGN KEY ("desciCommunityId") REFERENCES "DesciCommunity"("id") ON DELETE SET NULL ON UPDATE CASCADE;
21 changes: 14 additions & 7 deletions desci-server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,19 @@ model DesciCommunity {
name String @unique
slug String? @unique
image_url String?
subtitle String? // short description
description String
keywords String[]
memberString String[] // string list of member names
links String[] // string list of links
hidden Boolean @default(false)
members User[]
endorsements NodeFeedItemEndorsement[]
CommunityMember CommunityMember[]
Attestation Attestation[]
NodeAttestation NodeAttestation[]
CommunitySelectedAttestation CommunitySelectedAttestation[]
AttestationTemplate AttestationTemplate[]
}

model CommunityMember {
Expand All @@ -607,13 +612,15 @@ model CommunityMember {

// Templates for creating a new attestation
model AttestationTemplate {
id Int @id @default(autoincrement())
name String @unique
description String
image_url String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Attestation Attestation[]
id Int @id @default(autoincrement())
name String @unique
description String
image_url String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Attestation Attestation[]
DesciCommunity DesciCommunity? @relation(fields: [desciCommunityId], references: [id])
desciCommunityId Int?
}

// A factory attestation, these are the base attestations that can be assigned to nodes
Expand Down
84 changes: 4 additions & 80 deletions desci-server/prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { prisma } from '../src/client.js';
import communitiesData from '../src/data/communities.json' assert { type: 'json' };
// import communitiesData from '../src/data/communities.json' assert { type: 'json' };
import researchFieldsData from '../src/data/fields.json' assert { type: 'json' };
import { asyncMap, attestationService, communityService } from '../src/internal.js';
// import { asyncMap, attestationService, communityService } from '../src/internal.js';
import { seedSocialData } from '../src/scripts/seed-social-data.js';

async function main() {
await prisma.user.upsert({
Expand Down Expand Up @@ -71,84 +72,7 @@ async function main() {
console.log('NODE ENV', process.env.NODE_ENV);
if (process.env.NODE_ENV === 'test') return;

const communities = await Promise.all(
communitiesData['communities'].map((community) =>
prisma.desciCommunity.upsert({
where: { name: community.name },
create: {
name: community.name,
description: community.description,
image_url: community.image_url,
keywords: community.keywords,
slug: community.slug,
},
update: {
description: community.description,
image_url: community.image_url,
keywords: community.keywords,
slug: community.slug,
},
}),
),
);

console.log('Communities SEEDED', communities);
const inserted = await asyncMap(communitiesData['attestations'], async (attestation) => {
const community = communities.find((c) => c.name === attestation.communityName);
if (!community) throw new Error(`${attestation.communityName} not found, check seed data and retry`);
const inserted = await prisma.attestation.upsert({
where: {
name: attestation.name,
},
create: {
communityId: community?.id,
name: attestation.name,
description: attestation.description,
image_url: attestation.image_url,
},
update: {
communityId: community?.id,
name: attestation.name,
description: attestation.description,
image_url: attestation.image_url,
},
});
let version = await prisma.attestationVersion.findFirst({ where: { attestationId: inserted.id } });
if (!version) {
console.log('Publish version for', attestation.communityName, ' =>', attestation.name);
version = await prisma.attestationVersion.create({
data: {
name: attestation.name,
description: attestation.description,
image_url: attestation.image_url,
attestationId: inserted.id,
},
});
}

if (attestation.communitySelected === true) {
const selected = await prisma.communitySelectedAttestation.findFirst({
where: { desciCommunityId: inserted.communityId, attestationId: inserted.id, attestationVersionId: version.id },
});

if (!selected) {
console.log(`Add to community entry Attestation`, attestation.name);
await prisma.communitySelectedAttestation.create({
data: {
desciCommunityId: inserted.communityId,
attestationId: inserted.id,
attestationVersionId: version.id,
required: true,
},
});
} else {
console.log(`FOUND community entry Attestation`, attestation.name);
}
}
return { ...inserted, versions: version, communitySelected: attestation.communitySelected };
});

console.log('Attestations SEEDED', inserted);
await seedSocialData();
}

main()
Expand Down
4 changes: 3 additions & 1 deletion desci-server/src/controllers/communities/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
communityService,
resolveLatestNode,
} from '../../internal.js';
import { logger as parentLogger } from '../../internal.js';
const logger = parentLogger.child({ module: 'communities/feed.ts' });

export const getCommunityFeed = async (req: Request, res: Response, next: NextFunction) => {
const curatedNodes = await communityService.getCuratedNodes(parseInt(req.params.communityId as string));
Expand Down Expand Up @@ -63,7 +65,7 @@ export const getAllFeeds = async (req: Request, res: Response, next: NextFunctio
};
});

// logger.info({ nodes }, 'CHECK Verification SignalS');
logger.info({ nodes }, 'CHECK Verification SignalS');
let data = await Promise.all(nodes.map(resolveLatestNode));
// data = data.sort((c1, c2) => c1.engagements.verifications - c2.engagements.verifications);
data = data.sort((c1, c2) => {
Expand Down
15 changes: 13 additions & 2 deletions desci-server/src/controllers/communities/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ const logger = parentLogger.child({ module: 'LIST COMMUNITIES' });
export const listCommunities = async (_req: Request, res: Response, _next: NextFunction) => {
const allCommunities = await communityService.getCommunities();
const pickedCommunities = allCommunities.map((community) =>
_.pick(community, ['id', 'name', 'description', 'image_url', 'keywords', 'slug']),
_.pick(community, [
'id',
'name',
'subtitle',
'memberString',
'hidden',
'links',
'description',
'image_url',
'keywords',
'slug',
]),
);

const communities = await asyncMap(pickedCommunities, async (community) => {
Expand All @@ -19,7 +30,7 @@ export const listCommunities = async (_req: Request, res: Response, _next: NextF
engagements,
};
});
logger.info({ communities });
logger.info({ communities: communities.length });

new SuccessResponse(communities).send(res);
};
Loading

0 comments on commit 42428f3

Please sign in to comment.