Skip to content

Commit

Permalink
Merge pull request #597 from desci-labs/comment-enhancement
Browse files Browse the repository at this point in the history
required uuid in schema and annotation backfill script
  • Loading branch information
shadrach-tayo authored Oct 28, 2024
2 parents 440dd3a + eae2593 commit 6068d92
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 779 deletions.
3 changes: 2 additions & 1 deletion desci-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"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",
"script:seed-community-member": "debug=* node --no-warnings --enable-source-maps --loader ts-node/esm ./src/scripts/seed-community-members.ts",
"script:backfill-annotations": "debug=* node --no-warnings --enable-source-maps --loader ts-node/esm ./src/scripts/backfill-annotations.ts",
"build": "rimraf dist && tsc && yarn copy-files; if [ \"$SENTRY_AUTH_TOKEN\" ]; then yarn sentry:sourcemaps; else echo 'SENTRY_AUTH_TOKEN not set, sourcemaps will not upload'; fi",
"copy-files": "copyfiles -u 1 src/**/*.cjs dist/",
"generate": "npx prisma generate",
Expand Down Expand Up @@ -176,4 +177,4 @@
"prisma": {
"seed": "node --no-warnings=ExperimentalWarning --loader ts-node/esm prisma/seed.ts"
}
}
}
2 changes: 1 addition & 1 deletion desci-server/src/routes/v1/attestations/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const commentSchema = z
.refine((links) => links.every((link) => dpidPathRegex.test(link)))
.optional(),
highlights: z.array(highlightBlockSchema).optional(),
uuid: z.string().optional(),
uuid: z.string(),
visible: z.boolean().default(true),
})
.refine((comment) => comment.body?.length > 0 || !!comment?.highlights?.length, {
Expand Down
31 changes: 31 additions & 0 deletions desci-server/src/scripts/backfill-annotations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { prisma } from '../client.js';

const main = async () => {
const annotations = await prisma.annotation.findMany({
where: { uuid: null },
include: { attestation: { select: { nodeUuid: true } } },
});
const fields = await prisma.$transaction(
annotations.map(({ id, ...annotation }) =>
prisma.annotation.upsert({
where: { id },
create: {
authorId: annotation.authorId,
body: annotation.body,
type: annotation.type,
nodeAttestationId: annotation.nodeAttestationId,
links: annotation.links,
visible: annotation.visible,
highlights: annotation.highlights,
uuid: annotation.uuid || annotation.attestation?.nodeUuid,
},
update: { uuid: annotation.attestation?.nodeUuid },
}),
),
);
console.log('Annotations fields updated', fields);
};

main()
.then((result) => console.log('Annotations backfilled', result))
.catch((err) => console.log('Error running script ', err));
3 changes: 3 additions & 0 deletions desci-server/test/integration/Attestation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,7 @@ describe('Attestations Service', async () => {
authorId: members[0].userId,
claimId: openCodeClaim.id,
body: 'review 1',
uuid: openCodeClaim.nodeUuid,
};
let res = await request(app)
.post(`/v1/attestations/comments`)
Expand All @@ -2264,6 +2265,7 @@ describe('Attestations Service', async () => {
authorId: members[1].userId,
claimId: openCodeClaim.id,
body: 'review 2',
uuid: openCodeClaim.nodeUuid,
};
res = await request(app).post(`/v1/attestations/comments`).set('authorization', memberAuthHeaderVal2).send(body);
expect(res.statusCode).to.equal(200);
Expand All @@ -2282,6 +2284,7 @@ describe('Attestations Service', async () => {
authorId: users[1].id,
claimId: openCodeClaim.id,
body: 'review 1',
uuid: openCodeClaim.nodeUuid,
});
expect(apiResponse.statusCode).to.equal(401);

Expand Down
Loading

0 comments on commit 6068d92

Please sign in to comment.