-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #531 from desci-labs/highlight-adaptation
Add support for Comments on Nodes
- Loading branch information
Showing
19 changed files
with
299 additions
and
67 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
...ns/20240925135142_add_uuid_and_visible_and_make_nodeattestation_id_optional/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- DropForeignKey | ||
ALTER TABLE "Annotation" DROP CONSTRAINT "Annotation_nodeAttestationId_fkey"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Annotation" ADD COLUMN "nodeId" INTEGER, | ||
ADD COLUMN "uuid" TEXT, | ||
ADD COLUMN "visible" BOOLEAN NOT NULL DEFAULT true, | ||
ALTER COLUMN "nodeAttestationId" DROP NOT NULL; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Annotation" ADD CONSTRAINT "Annotation_nodeAttestationId_fkey" FOREIGN KEY ("nodeAttestationId") REFERENCES "NodeAttestation"("id") ON DELETE SET NULL ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Annotation" ADD CONSTRAINT "Annotation_uuid_fkey" FOREIGN KEY ("uuid") REFERENCES "Node"("uuid") ON DELETE SET NULL ON UPDATE CASCADE; |
8 changes: 8 additions & 0 deletions
8
...erver/prisma/migrations/20240926094958_remove_nodeid_column_from_annotation/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `nodeId` on the `Annotation` table. All the data in the column will be lost. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Annotation" DROP COLUMN "nodeId"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Response, NextFunction } from 'express'; | ||
import _ from 'lodash'; | ||
import z from 'zod'; | ||
|
||
import { | ||
NotFoundError, | ||
RequestWithNode, | ||
SuccessResponse, | ||
attestationService, | ||
ensureUuidEndsWithDot, | ||
getCommentsSchema, | ||
logger, | ||
prisma, | ||
} from '../../internal.js'; | ||
|
||
export const getGeneralComments = async (req: RequestWithNode, res: Response, _next: NextFunction) => { | ||
const { uuid } = req.params as z.infer<typeof getCommentsSchema>['params']; | ||
const node = await prisma.node.findFirst({ where: { uuid: ensureUuidEndsWithDot(uuid) } }); | ||
if (!node) throw new NotFoundError("Can't comment on unknown research object"); | ||
|
||
const restrictVisibility = node.ownerId !== req?.user?.id; | ||
|
||
logger.info({ restrictVisibility }, 'Query Comments'); | ||
const comments = await attestationService.getComments({ | ||
uuid: ensureUuidEndsWithDot(uuid), | ||
...(restrictVisibility && { visible: true }), | ||
}); | ||
|
||
const data = comments.map((comment) => { | ||
const author = _.pick(comment.author, ['id', 'name', 'orcid']); | ||
return { ...comment, author, highlights: comment.highlights.map((h) => JSON.parse(h as string)) }; | ||
}); | ||
|
||
return new SuccessResponse(data).send(res); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.